智能销售系统CRUD

删除功能

delete() {
    //先判断有没有选中
    var row = employeeDataGrid.datagrid("getSelected");
    //没有选中就给出提示
    if (!row) {
        $.messager.alert("提示", "请选中", "info");
        return;
    }
    //选中就让用户是否确认删除
    $.messager.confirm('确认删除', '真的狠心删除我吗', function (r) {
        if (r) {
            //确认删除直接访问后台
            $.get("/employee/delete", {id: row.id}, function (result) {
                if (result.success) {
                    //成功后刷新
                    employeeDataGrid.datagrid("reload");
                } else {
                    $.messager.alert("提示", `出错了,原因是:${result.msg}`, "error");
                }
            })
        }
    })
}

添加的时候显示密码,并启用
修改的时候隐藏密码,并禁用

添加功能

引入验证

<%--验证扩展的样式与js引入--%>
<link rel="stylesheet" type="text/css" href="/easyui/plugin/validatebox/jeasyui.extensions.validatebox.css">
<script src="/easyui/plugin/validatebox/jeasyui.extensions.validatebox.rules.js"></script>

添加

add() {
    //把所有带data-show的元素显示起来
    $("*[data-show]").show();
    //开启验证功能
    $("*[data-show] input").validatebox("enable");
    //打开对话框
    employeeDialog.dialog("center").dialog("open");
    //把form中的数据清空
    employeeForm.form("clear");
},

自定义验证

//定义我们自己的规则(验证重复)
$.extend($.fn.validatebox.defaults.rules, {
    checkName: {
        //验证规则  value:表单中的值  params:规则中传过来的值(数组形式)
        validator: function(value, param){
            //拿到相应的id
            var employeeId = $("#employeeId").val();
            //使用同步的方式进行查询
            var isSuccess = $.util.requestAjaxBoolean('/employee/checkUsername',
                {id:employeeId,username:value});
            //使用同步的方式进行Ajax请求
           return isSuccess;
        },
        //验证失败的提示
        message: '用户名已经被占用!'
    }
});

修改功能

edit() {
    var row = employeeDataGrid.datagrid("getSelected");
    if (!row) {
        $.messager.alert("提示", "请选中", "info");
        return;
    }
    //把有data-show的所有的元素隐藏起来
    $("*[data-show]").hide();
    //让验证的失效
    $("*[data-show] input").validatebox("disable");
    //打开对话框
    employeeDialog.dialog("center").dialog("open");
    //把form表单中的数据清空
    employeeForm.form("clear");
    if (row.department) {
        row["department.id"] = row.department.id;
    }
    //完成回显
    employeeForm.form("load", row);
}

数据丢失问题

  @ModelAttribute("editEmployee")//odelAttribute : 在路径访问这个方法的时候会先执行它
    public Employee beforeEdit(Long id,String cmd){
        //修改的时候才查询(只要有id会就进行一次查询,这是不对的)
        if(id!=null && "update".equals(cmd)) {
            Employee dbEmp = employeeService.findOne(id);
            //把要传过来的关联对象都清空,就可以解决n-to-n的问题
            dbEmp.setDepartment(null);
            return dbEmp;
        }
        return null;
    }
    
    //这里的ModelAttribute和上面的名称是对应上的
    @RequestMapping("/update")
    @ResponseBody
    public JsonResult update(@ModelAttribute("editEmployee")Employee employee){
        return saveOrUpdate(employee);
    }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值