问题描述
提示:这里描述项目中遇到的问题:
调用如下代码时
<!--List<Star> queryStarsById(@Param("sids")List<Integer> sids);-->
<select id="queryStarsByIds" resultType="searchEngine.entity.Star">
select * from star
<where>
star_id in
<foreach item="sid" index="index"
collection="sids" open="(" separator="," close=")" nullable="true">
#{sid}
</foreach>
</where>
</select>
报错如下
### SQL: select * from star WHERE star_id in
### Cause: java.sql.SQLSyntaxErrorException: 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
; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: 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] with root cause
原因分析:
提示:这里填写问题的分析:
暂时未知,可能是版本问题
解决方案:
提示:这里填写该问题的具体解决方案:
将star_id in
写入内部,代码如下:
<!--List<Star> queryStarsById(@Param("sids")List<Integer> sids);-->
<select id="queryStarsByIds" resultType="searchEngine.entity.Star">
select * from star
<where>
<foreach item="sid" index="index"
collection="sids" open="star_id in (" separator="," close=")" nullable="true">
#{sid}
</foreach>
</where>
</select>