直接上代码
@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与(之间,我把之间的空格去了就正确了,请问这到底是什么原因啊。。。。。。。。