我有表格绑定(bind)
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "boundId", unique = true, nullable = false)
private long boundId;
@Column
@Basic
private Timestamp startTimeStamp;
@Column
@Basic
private Timestamp endTimeStamp;
我创建了查询:
public interface BoundsDataRepository extends CrudRepository<Bound, Long> {
@Query("from Bound b where b.startTimeStamp s <=:currentTimeStamp and b.endTimeStamp e>=:currentTimeStamp")
List<Bound> findByCurrentTimeStamp(Timestamp currentTimeStamp);
}
我给我一个错误。我应该如何命名这个查询以及如何解决这个问题?
感谢您的帮助!
最佳答案
我认为您的查询存在一些问题:
- 您不需要在列名称中使用别名
b.endTimeStamp e
- 您使用参数
:currentTimeStamp
但未在查询中传递任何参数
您的查询应如下所示:
@Query("from Bound b where b.startTimeStamp <= :currentTimeStamp and "
+ "b.endTimeStamp >= :currentTimeStamp")
List<Bound> findByCurrentTimeStamp(@Param("currentTimeStamp") Timestamp currentTimeStamp);
关于java - CrudRepository 按当前时间戳自定义查找,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47691995/