java spring boot中使用Mysql函数 [英] Using Mysql function in java spring boot
本文介绍了java spring boot中使用Mysql函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的存储库中的自定义查询有一个小问题:
Got a little problem with custom query in my repository:
@Query("select v from Visit v where YEARWEEK('date') = YEARWEEK(curdate())")
在 YEARWEEK('date') 左括号前显示错误:
Error shows before YEARWEEK('date') opening bracket:
<expression>, <operator>, AND, GROUP, HAVING, IS, OR or ORDER expected, got '('
推荐答案
您有两个选择:
对于 HQL,您需要以下内容:
For HQL you need following:
@Query("select * from Visit v where YEARWEEK('v.date') = YEARWEEK(curdate())")
您也可以使用本机查询,在这种情况下,您需要遵循(这不是 Spring 应用程序的最佳方式,但可用于某些情况)
You can have native query also, in that case you need following (not the best way for Spring applications, though can be used for some cases)
@Query(value = "select * from Visit where YEARWEEK('date') = YEARWEEK(curdate())", nativeQuery = true)
这篇关于java spring boot中使用Mysql函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文