java根据id批量删除
1.mapper.xml
传入的参数可以是List也可以是Array数组,ParameterType都写List就可以 collection="array"也可以写成collection=“lsit”
<!--批量删除--> <delete id="deleteMenuIds" parameterType="java.util.List"> delete from sys_menu where menu_id in <foreach collection="array" open="(" close=")" separator="," item="id"> #{id} </foreach> </delete>
2.dao层
int deleteMenuIds(Long[] ids);
3.pojo层
package com.qingfeng.pojo; import java.io.Serializable; public class SysMenu implements Serializable { private Long menuId; private Long parentId; private String name; private String url; public Long getMenuId() { return menuId; } public void setMenuId(Long menuId) { this.menuId = menuId; } public Long getParentId() { return parentId; } public void setParentId(Long parentId) { this.parentId = parentId; } public String getName() { return name; } public void setName(String name) { this.name = name == null ? null : name.trim(); } public String getUrl() { return url; } public void setUrl(String url) { this.url = url == null ? null : url.trim(); } }
4.service层
public R deleteMenu(Long[] ids) { int i = sysMenuMapper.deleteMenuIds(ids); if (i>0){ return R.ok(); }else { return R.error("删除失败"); } }
5.controller层
@PostMapping("/sys/delete") @ResponseBody public R del(Long[] ids){ return sysMenuService.deleteMenu(ids); }
6.测试
http://localhost:8080/sys/delete?ids=1,2,5