Is there a simplified method to delete associated data? If it is 45678 layer Association, do you need to judge one by one (language Java)

CSDN Q & A 2022-05-15 04:43:49 阅读数:79

simplifiedmethoddeleteassociateddata
problem

If it is multi-level association deletion, is there a good solution ?

 public Result removePermissions(List<SysPermissions> permissionsList) { if (permissionsList.size() == 0) { return ResultData.fail(ResultMsg.PARAMS_ERROR); } // Traverse delete associated data  for (SysPermissions sysPermissions : permissionsList) { long menuExist = sysPermissionsMapper.selectCount(new QueryWrapper<SysPermissions>() .eq(SysPermissions.PARENT_ID,sysPermissions.getId()) .last("limit 1")); if (menuExist > 0) { List<SysPermissions> menuList = sysPermissionsMapper.selectList(new QueryWrapper<SysPermissions>() .eq(SysPermissions.PARENT_ID,sysPermissions.getId())); for (SysPermissions permissions : menuList) { long eventExist = sysPermissionsMapper.selectCount(new QueryWrapper<SysPermissions>() .eq(SysPermissions.PARENT_ID,permissions.getId()) .last("limit 1")); if (eventExist > 0) { List<SysPermissions> eventList = sysPermissionsMapper.selectList(new QueryWrapper<SysPermissions>() .eq(SysPermissions.PARENT_ID,permissions.getId())); sysPermissionsMapper.deleteBatchIds(eventList); } } sysPermissionsMapper.deleteBatchIds(menuList); } } return ResultData.auto(sysPermissionsMapper.deleteBatchIds(permissionsList) > 0); }



Take the answer :

Delete association has 2 Ways of planting :1.java Code mode : Delete in batch or one by one , First, there must be parameters such as deleted primary keys , Query the primary key of the associated table , Then delete the associated table data in turn .2. Database mode :https://blog.csdn.net/zou666zou/article/details/122752746


版权声明:本文为[CSDN Q & A]所创,转载请带上原文链接,感谢。 https://primo.wiki/2022/131/202205041842476300.html