版权声明:本文由 低调小熊猫 发表于 低调小熊猫的博客
转载声明:自由转载-非商用-非衍生-保持署名,非商业转载请注明作者及出处,商业转载请联系作者本人qq:2696284032
文章链接: https://aodeng.cc/archives/deletebug
如图,我开始复制delete语句和参数到数据库执行,删除两条数据,但是后台执行确只删除一条数据,当时表示一脸懵逼
如图,正确的参数传值应该是这样的,聪明的同学,应该就知道哪里错了
我就不贴开始的代码了,直接贴解决bug的代码
mybatis中的代码
<!-- 批量删除--> <delete id="deleteByIds" parameterType="int[]"> <![CDATA[ DELETE FROM p_customer WHERE customerId in ]]> <foreach collection="array" item="arr" index="no" open="(" separator="," close=")"> #{arr} </foreach> </delete>
/** * 删除和批量删除 */ @RequestMapping(value = "/del", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE }) public ResponseEntity<PCustomerVo> delete(@RequestParam String customerId) throws Exception { //获取批量删除的id,去掉最后一个“,” customerId=customerId.substring(0,customerId.length()-1); String[] strarr=customerId.split(","); int[] arr=new int[strarr.length]; for(int i=0;i<strarr.length;i++){ arr[i]=Integer.parseInt(strarr[i]); } pcustomerService.deletes(arr); return new ResponseEntity<>(HttpStatus.OK); }