解决MySQL报错Error querying database. 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.
### Error querying database. 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 'title = 'xxx'' at line 3
### The error may exist in com/lanyy/dao/BlogMapper.xml
### The error may involve com.lanyy.dao.BlogMapper.queryBlogIF-Inline
### The error occurred while setting parameters
### SQL: select * from blog where 1=1 title = ?
### 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 'title = 'xxxx'' at line 3
复制代码
2.问题排查
where之后需接条件语句,需写where 1=1,假如引入标签则不要再写,标签会主动添加执行
3.问题解决
引入<where>标签子句 where元素只会在至少有一个子元素的条件满足情况下才去插入 \ 查询, 这个“where”标签会知道假如它输入的信息中包含的标签有返回值(参数)的话,它就插入一个‘where’条件。 此外,假如标签返回的内容是以AND 或 OR 开头的,则它会剔除掉AND或OR。