部门dept的删除数据
如果要删除的数据没有给其它部门作上级,则删除成功。反之删除失败 在dao层中添加一个方法查找,然后作判断,看是否有给其它部门作上级 先查询下级部门有几个,再删除。如果有则删除失败,没有则删除成功
TestDeptService
@Test
public void test06 ( ) {
String deptId= "100" ;
boolean result= service. deleteDeptById ( deptId) ;
l. info ( "result==" + result) ;
}
IDeptService
boolean deleteDeptById ( String deptId) ;
DeptServiceImpl
@Override
public boolean deleteDeptById ( String deptId) {
int count= dao. findParentCount ( deptId) ;
if ( count== 0 ) {
dao. deleteDeptById ( deptId) ;
return true ;
}
return false ;
}
IDeptDao
int findParentCount ( String deptId) ;
void deleteDeptById ( String deptId) ;
IDeptDao.xml
< select id = " findParentCount" parameterType = " string" resultType = " int" >
select count(*) from pe_dept where parent_id=#{deptId}
</ select>
< delete id = " deleteDeptById" parameterType = " string" >
delete from pe_dept where dept_id=#{deptId}
</ delete>
DeptController
@RequestMapping ( path = "/delete" , method = { RequestMethod. GET} )
public String delete ( String deptId) {
l. info ( "delete deptId==" + deptId) ;
service. deleteDeptById ( deptId) ;
return "redirect:/system/dept/toList.do" ;
}
dept-list.jsp
< script>
function deleteById ( ) {
var deptId = getCheckId ( )
if ( deptId) {
if ( confirm ( "你确认要删除此条记录吗?" ) ) {
location. href= "${path}/system/dept/delete.do?deptId=" + deptId;
}
} else {
alert ( "请勾选待处理的记录,且每次只能勾选一个" )
}
}
</ script>