我尝试在Spring Boot中使用MySQL原生查询在dateFrom和当前日期之间使用select查询来获取列表形式的表数据。MySQL数据库字段数据类型为字符串。
以下是存储库中的查询:
@Query(value = "select * from Account where DATETIMESTAMP >= :dateFrom AND DATETIMESTAMP < :DATE_FORMAT(curdate(), '%d/%m/%Y')", nativeQuery = true)
List<Account> findByDate(@Param("dateFrom") String dateFrom);在Spring Boot中获取上述查询的以下错误:
Named parameter not bound : DATE_FORMAT; nested exception is org.hibernate.QueryException: Named parameter not bound : DATE_FORMAT有没有人可以帮我把这个查询框起来。
发布于 2020-10-14 22:01:19
从:DATE_FORMAT(curdate(), '%d/%m/%Y')中删除:。:用于绑定jpa查询中的参数。DATE_FORMAT前面添加的:使JPA认为它是一个参数。所以最后的查询应该是
@Query(value = "select * from Account where DATETIMESTAMP >= :dateFrom AND DATETIMESTAMP < DATE_FORMAT(curdate(), '%d/%m/%Y')", nativeQuery = true)
List<Account> findByDate(@Param("dateFrom") String dateFrom);https://stackoverflow.com/questions/64354458
复制相似问题