java:mybatis
Mybatis坑爹问题A
就因为这么写代码
<select id="queryLinksByGroupIds" resultType="com.xiaosq.projectx.dal.module.Link" parameterType="java.util.List"> select l.* from link as l INNER JOIN group_link as gl ON l.id = gl.link_id where gl.group_id in <foreach item="item" collection="list" open="(" separator="," close=")"> #{item} </foreach> </select>
然后一直报这个错:
### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column ' 2' in 'where clause' ### The error may exist in file [D:\gitee\projectx\projectx-dal\target\classes\mapper\LinkMapper.xml] ### The error may involve com.xiaosq.projectx.dal.mapper.LinkMapper.queryLinksByGroupIds-Inline ### The error occurred while setting parameters ### SQL: select l.* from link as l INNER JOIN group_link as gl ON l.id = gl.link_id where gl.group_id in ( ? , ? ) ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column ' 2' in 'where clause' ; bad SQL grammar []
解决办法就是把代码中 #{item} 给移到行头, 因为这个前面之前 有一个tab键
java/mybatis.txt · Last modified: 2019/12/18 03:49 by 127.0.0.1