做一个应用查数据库,用了spring-boot的CrudRepository,想查询一个时间段里的数据
查询一个时间之后,方法返回的结果正常
List<T> findByTimestampAfter(@Param("timestamp") Date start)
查询一个时间之前,方法返回的结果也正常
List<T> findByTimestampBefore(@Param("timestamp") Date end)
但是我试了下面三种方法都不行:
List<T> findByTimestampBetween(@Param("timestamp") Date start,@Param("timestamp") Date end)
List<T> findByTimestampAfterAndTimestampBefore(@Param("timestamp") Date start,@Param("timestamp") Date end)
List<T> findByTimestampGreaterThanEqualAndTimestampLessThanEqual(@Param("timestamp") Date start,@Param("timestamp") Date end)
返回的结果是timestamp正好等于end的一条数据,而中间应该有100多条数据
反复看文档,还是认为代码没写错
在数据库直接select * from exchange where timestamp > "2018-01-02 17:30:00" AND timestamp < "2018-01-02 17:48:00"; 结果也是正确的
真是奇怪了。。。
原来两个参数不能写一个名字
@Param("timestamp") Date start,@Param("timestamp") Date end
改为
@Param("start") Date start,@Param("end") Date end
就可以了