简体   繁体   English

如何使用 localdate 创建 hibernate 请求

[英]How to create hibernate request with localdate

I have a user who has an expiration date (dateTime), I need to display all users who have not expired yet.我有一个有过期日期(dateTime)的用户,我需要显示所有尚未过期的用户。 Tried different options with DATA (), or as an example -用 DATA () 尝试了不同的选项,或者作为一个例子 -

@Query (name = "SELECT u FROM User u WHERE u.date>: now")
     Page <User> findByMute (@Param ("now") LocalDateTime now, Pageable pageable);

but it doesn't output anything.但它没有 output 任何东西。 But when asked in MySQL - SELECT * FROM user where user.date> NOW () displays everything as it should.但是当在 MySQL - SELECT * FROM user where user.date> NOW () 中询问时,会按应有的方式显示所有内容。 Tell me how to implement this query in Hibernate?告诉我如何在 Hibernate 中实现这个查询?

Replace annotation attribute " name " with " value ":将注解属性“ name ”替换为“ value ”:

@Query(value = "SELECT u FROM User u WHERE u.date>:now")
Page<UserEntity> findByMute(@Param("now") LocalDateTime now, Pageable pageable);

The annotation attribute " name " always refers to a named query, while the attribute " value " can be used to specify a query.注释属性“ name ”总是指一个命名查询,而属性“ value ”可以用来指定一个查询。 " value= " can be omitted, so this works too: value= " 可以省略,所以这也有效:

@Query("SELECT u FROM UserEntity u WHERE u.date>:now")
Page<UserEntity> findByMute(@Param("now") LocalDateTime now, Pageable pageable);

See https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.at-query for details.有关详细信息,请参阅https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.at-query

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM