代码示例为MyBatis的
给sql语句一个 foreach循环,至于为什么不用for,因为不知道循环几次
传过来的是一个对象数组 !!对象数组!! 对象数组!!
@Insert(" <script> " +
" INSERT INTO `ceshi (`name`, `sex`) VALUES " +
" <foreach collection='ceshiList' item='cs' separator=','> " +
" (#{cs.name},#{cs.sex}) " +
" </foreach> " +
" </script> "
)
int ceshi(CeshiParam ceshiParam);
如果是修改删除
需要括号open=’(’ close=’)'
//修改员工状态
@Update("<script>" +
" update app_staffapi set status=3 where companyid = #{companyid} and id in " +
" <foreach collection='ids' item='id' separator=',' open='(' close=')'> " +
" #{id} " +
" </foreach> " +
"</script>")
int s(@Param("arr") int[] arr);
注意@Param 这个注解很重要,可以去百度下
不加注释 报错 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
org.apache.ibatis.binding.BindingException: Parameter ‘arr’ not found. Available parameters are [array]