public interface ContentCatService
//删除
public void delete(Integer id) throws Exception;
public class ContentCatServiceImpl implements ContentCatService
//删除
public void delete(Integer id) throws Exception {
//1.基于id进行子元素查询
int count = contentCatMapper.getChildCount(id);
if(count>0) throw new Exception("请先删除子菜单");
//2.删除菜单元素
int rows= contentCatMapper.deleteObject(id);
if(rows==0) throw new Exception("此菜单可能已经不存在");
//3.删除角色,菜单关系数据
contentMapper.deleteObjectsByMenuId(id);
}
public class ContentCatController
//删除
@RequestMapping(value = "/delete", method = RequestMethod.GET)
private SysResult delete(Integer id){
try {
contentCatService.delete(id);
return SysResult.ok();
}catch (Exception e){
e.printStackTrace();
return SysResult.build(201,"删除失败");
}
}
public interface ContentCatMapper extends BaseMapper
@Select("select count(*) from mt_content_category where parent_id=#{id}")
int getChildCount(Integer id);
@Select("delete from mt_content_category where id=#{id}")
int deleteObject(Integer id);
public interface ContentMapper extends BaseMapper
@Select("delete from mt_content where category_id=#{id}")
int deleteObjectsByMenuId(Integer categoryId);
然后执行结果成功,返回参数失败,然后报异常了
有大佬可以帮忙看看吗