功能说明 删除时应该删除子节点,有两个方式:1.通过一条SQL语句进行删除 2.执行两个删除语句。 数据源增加 &allowMultiQueries=true JAVA 后端 dao
void deleteDeptById(int id);mapper
<!--删除操作 根据id删除节点以及下面的子节点--> <delete id="deleteDeptById" parameterType="int"> delete from dept where id=#{id} or id in (SELECT t3.id FROM ( SELECT *, IF (find_in_set(t1.parent_Id, @p) >0,@p:= concat(@p,',',id),0) AS childId FROM (SELECT id,parent_Id FROM dept t ORDER BY id) t1, (SELECT @p:= #{id} ) t2 ) t3 WHERE childId != 0) ; </delete>service 接口
void deleteDeptById(int id);实现
@Override public void deleteDeptById(int id) { iDeptDao.deleteDeptById(id); }控制层
@RequestMapping("dept/deleteDeptByID") @ResponseBody public R deleteDeptByID(int id){ deptService.deleteDeptById(id); return R.ok(); }前端
测试 后记 因为涉及多层树,所以删除SQL语句还是需要多熟悉一下。