saas-export项目---部门dept的删除

部门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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值