我遇到一个奇怪的问题,myBaits关于foreach批量删除数据出错的问题,求解。。。。。

丶顛簸人生 2015-08-27 05:22:18
直接上代码



@Controller的实现
public void deleteContent(@RequestParam(value = "funtionId[]") Integer[] funtionId){
List<Integer> list = Arrays.asList(funtionId);
contentManageService.deleteContent(list);
}

@Service和dao都直接调用的,接下来我们看下mapper文件

<delete id="deleteContent" parameterType="java.util.List" >
delete from t_function where 1=1
<if test="list != null and list.size>0">
and f_id in
 <foreach item="item" index="index" collection="list"
open="(" separator="," close=")">
#{item}
</foreach>
</if>
</delete>


错误信息:提示语法错误!!
SEVERE: Servlet.service() for servlet [SpringMVC] in context with path [/cfsdc_template] threw exception [Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException:
### Error updating 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 '  (
10
)' at line 4
### The error may involve com.cfsdc.template.dao.IContentManageDao.deleteContent-Inline
### The error occurred while setting parameters
### SQL: delete from t_function where 1=1 and f_id in   ( ? )
### 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 '  (
10
)' at line 4
; bad SQL grammar []; nested exception is 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 '  (
10
)' at line 4] with root cause


附:我直接把这sql语句放到mysql中执行确实报错delete from t_function where 1=1 and f_id in   ( ? ),问题出现在in   ( ? ) in与(之间,我把之间的空格去了就正确了,请问这到底是什么原因啊。。。。。。。。
...全文
187 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
建议你看下你list的数据
gukuitian 2015-08-27
  • 打赏
  • 举报
回复
k the manual that corresponds to your MySQL server version for the right syntax to use near '  ( 10 )' 反正你这行提示里,是有个中文空格 ,在引号后,一中文,一英文空格 实在不行就整个sql删了,重写下.
丶顛簸人生 2015-08-27
  • 打赏
  • 举报
回复
引用 1 楼 gukuitian 的回复:
你那之间是不是加中文全角空格了?
没有啊,我都检查几遍了,我开始也以为是这问题!!!!!!
gukuitian 2015-08-27
  • 打赏
  • 举报
回复
你那之间是不是加中文全角空格了?

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧