按当前时间戳

时间:2017-12-07 09:43:35

标签: java sql spring-data-jpa crud

我有表格绑定

@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);
}

我给了我一个错误。我该如何命名此查询以及如何解决此问题?

感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

我认为您的查询存在一些问题:

  • 您无需在列名b.endTimeStamp e
  • 中使用别名
  • 您使用参数:currentTimeStamp,但未在查询中传递任何参数

您的查询应如下所示:

@Query("from Bound b where b.startTimeStamp <= :currentTimeStamp and "
        + "b.endTimeStamp >= :currentTimeStamp")
List<Bound> findByCurrentTimeStamp(@Param("currentTimeStamp") Timestamp currentTimeStamp);