SSM框架整合项目03 修改,删除功能的实现

修改功能

流程:点击编辑,弹出修改页面(显示用户信息),点击更新,完成修改

生成修改页面,并回显员工信息

前端代码

index.jsp

修改页面

<!-- 修改页面 -->
<div class="modal fade" id="empUpdateModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">员工修改</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">姓名</label>
                        <div class="col-sm-10">
                            <p class="form-control-static" id="empName_update_static"></p>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">邮箱</label>
                        <div class="col-sm-10">
                            <input type="text" name="email" class="form-control" id="email_update_input"
                                   placeholder="请输入邮箱(例:xxx@gyq.com)">
                            <span class="help-block"></span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">性别</label>
                        <div class="col-sm-10">
                            <label class="radio-inline">
                                <input type="radio" name="gender" id="gender1_update_input" value="男"
                                       checked="checked"> 男
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="gender" id="gender2_update_input" value="女"> 女
                            </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">部门</label>
                        <div class="col-sm-4">
                            <select class="form-control" name="dId" id="dept_update_select">

                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" id="emp_update_btn">更新</button>
            </div>
        </div>
    </div>
</div>
</div>

编辑按钮绑定单击事件

后端代码

EmpController

    //查询员工信息的方法
    @ResponseBody
    @RequestMapping(value = "emp/{id}", method = RequestMethod.GET)
    public Msg getEmp(@PathVariable("id") Integer id) {
        Employee employee = employeeService.getEmp(id);
        return Msg.success().add("emp", employee);
    }

EmpService

    public Employee getEmp(Integer id) {
        Employee employee = employeeMapper.selectByPrimaryKey(id);
        return employee;
    }

点击更新,更新员工数据

EmployeeController

    //更新员工信息
    @ResponseBody
    @RequestMapping(value = "/emp/{empId}", method = RequestMethod.PUT)
    public Msg updateEmp(Employee employee) {
        employeeService.updateEmp(employee);
        return Msg.success();
    }

EmployeeService

    public void updateEmp(Employee employee) {
        employeeMapper.updateByPrimaryKeySelective(employee);
    }

前端代码,部分

    //点击更新按钮更新员工数据
    $("#emp_update_btn").click(function () {
        //校验邮箱信息
        var email = $("#email_update_input").val();
        var regEmail = /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/;
        if (!regEmail.test(email)) {
            show_validate_msg("#email_update_input", "error", "邮箱格式不正确!");
            return false;
        } else {
            show_validate_msg("#email_update_input", "success", "");
        }
        //发送ajax请求保存更新的员工数据
        $.ajax({
            url: "${pageContext.request.contextPath }/emp/" + $(this).attr("edit-id"),
            type: "post",
            data: $("#empUpdateModal form").serialize() + "&_method=put",
            success: function (result) {
                //关闭编辑框
                $("#empUpdateModal").modal('hide');
            }
        });
    });

上方代码没有如下问题

注意:ajax直接发送put请求时,Tomcat不会将携带的数据封装到map中,request请求体和本应封装的对象的相应属性为null

在web.xml中配置FormContentFilter解决,拦截/*

删除功能

删除单一员工

前端

    //单个删除
    $(document).on("click", ".delete_btn", function () {
        //弹出是否确认删除
        var empName = $(this).parents("tr").find("td:eq(1)").text();
        var empId = $(this).attr("del-id");
        if (confirm("确认删除[" + empName + "]吗?")) {
            $.ajax({
                url: "${pageContext.request.contextPath }/emp/" + empId,
                type: "post",
                data: "&_method=delete",
                success: function (result) {
                    alert(result.msg);
                    to_page(currentPage);
                }
            });
        }
    });

后端

EmployeeControlller

    //删除员工信息
    @ResponseBody
    @RequestMapping(value = "/emp/{id}", method = RequestMethod.DELETE)
    public Msg deleteEmpById(@PathVariable("id") Integer id) {
        employeeService.deleteEmp(id);
        return Msg.success();
    }

EmployeeService

    public void deleteEmp(Integer id) {
        employeeMapper.deleteByPrimaryKey(id);
    }

批量删除

更改显示员工数据的表头

解析展示员工数据,新增一列

这里加了一个td,前面单个删除获取用户名时,就要获取第三个td的值

全选全不选

点击删除按钮删除选中记录

    //批量删除
    $("#emp_delete_all_btn").click(function () {
        var empNames = "";
        var del_idstr = "";
        $.each($(".check_item:checked"), function () {
            empNames += $(this).parents("tr").find("td:eq(2)").text() + " ";
            del_idstr += $(this).parents("tr").find("td:eq(1)").text() + "-";
        });
        del_idstr = del_idstr.substring(0, del_idstr.length - 1);
        if (confirm("确认删除" + empNames + "吗?")) {
            //发送ajax请求删除
            $.ajax({
                url: "${pageContext.request.contextPath }/emp/" + del_idstr,
                type: "delete",
                data: "&_method=delete",
                success: function (result) {
                    alert(result.msg);
                    to_page(currentPage);
                }
            });
        }
    });

修改刚才的单个删除方法,使其能够批量删除

EmployeeService

总结

  • 2
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
教务系统是一个管理学生、教师、课程等信息的系统,它是现代高校管理的重要工具之一。基于SSM框架的教务系统项目,主要包括以下几个模块: 1. 用户管理模块:包括管理员、教师、学生等用户的注册、登录、修改密码、个人信息管理等功能。 2. 课程管理模块:包括课程的添加、修改删除、查询等功能。 3. 学生管理模块:包括学生的添加、修改删除、查询、选课等功能。 4. 教师管理模块:包括教师的添加、修改删除、查询、授课等功能。 5. 成绩管理模块:包括成绩的录入、查询、统计等功能。 6. 系统管理模块:包括系统参数设置、日志管理、数据备份等功能。 在实现教务系统项目时,需要使用SSM框架进行开发。SSM框架是Spring、SpringMVC和MyBatis三个框架的结合,它们分别负责业务逻辑、Web层和数据访问层的处理,通过整合这三个框架,可以提高开发效率,降低系统复杂度。 在使用SSM框架开发教务系统项目时,需要按照以下步骤进行: 1. 构建Maven项目:使用Maven构建一个基于SSM框架的Web项目。 2. 配置Spring:在项目中配置Spring框架,包括配置数据源、事务管理器、数据访问层等。 3. 配置SpringMVC:在项目中配置SpringMVC框架,包括配置控制器、视图解析器、拦截器等。 4. 配置MyBatis:在项目中配置MyBatis框架,包括配置DAO层、映射文件、SQL语句等。 5. 开发业务逻辑:根据教务系统的需求,开发相应的业务逻辑,包括用户管理、课程管理、学生管理、教师管理、成绩管理等。 6. 开发前端页面:根据教务系统的需求,开发相应的前端页面,包括登录页面、注册页面、个人信息管理页面、课程管理页面、学生管理页面、教师管理页面、成绩管理页面等。 7. 调试测试:在开发完毕后,对系统进行调试测试,确保系统正常运行。 总之,基于SSM框架的教务系统项目开发需要综合运用Spring、SpringMVC和MyBatis三个框架,同时需要根据教务系统的需求,开发相应的业务逻辑和前端页面,最终确保系统正常运行。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值