这是SQL代码,用的时mybatis的注解
@Select("select * from t_chushou where (title like CONCAT('%',#{0},'%')")
错误信息是:
SQL: select * from t_chushou WHERE (title like CONCAT("%",?,"%")
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 2
我用数据库软件直接运行代码段,发现第一个‘%’后面就好像没用了。。。大神帮我看看呗
where (title 这里多了个“(”
这样试试: select * from t_chushou where (title like CONCAT('%',${0},'%')
# 换成 $
#{0}是你传的参数,在mysql中不能用,select * from t_chushou where (title like CONCAT('%',‘需要查询的内容’,'%')
https://baike.baidu.com/item/concat%28%29/13473511?fr=aladdin
三个字符连接需要嵌套使用,而且你传入的字符完全可以写成 '%需要传入的字符%'以这种形式传入SQL
你也不觉得自己缺少一个括号吗