简体   繁体   中英

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. Tried different options with DATA (), or as an example -

@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. But when asked in MySQL - SELECT * FROM user where user.date> NOW () displays everything as it should. Tell me how to implement this query in Hibernate?

Replace annotation attribute " name " with " 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. " value= " can be omitted, so this works too:

@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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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