@Query("select t from PartialDischargeForecast t where t.monitoringName =?1 and t.futureTime = ?2")
List<PartialDischargeForecast> queryByName(String name,Date date);
jpa中这样一句把时间作为参数传入作条件查询时,返回没有结果。查看后台的sql日志,输出的sql又是正确的。
并且将后台打印该方法执行的sql直接放在数据库中执行时,又能查询到数据,奇怪!
原因不明。不过解决办法倒是有,在方法定义入参时,给时间类型的参数加上注解 @Temporal(TemporalType.TIMESTAMP),进行查询即可生效
@Query("select t from PartialDischargeForecast t where t.monitoringName =?1 and t.futureTime = ?2")
List<PartialDischargeForecast> queryByName(String name,@Temporal(TemporalType.TIMESTAMP) Date date);