Preface:

The integration of SpringMVC,Mybatis,Spring three frameworks, the system based on Maven to do dependency management. The common functions in MIS system are realized by using MySQL database.


Techniques used:

  • Integration of SpringMVC,Mybatis and Spring frameworks;
  • The front-end framework integrates Bootstrap, Jquery, Bootstrap plug-in Bootgrid data table to achieve paging (paging case tutorial), background paging using Mybatis plug-in PageHelper to achieve
  • The realization of the increase, deletion, change and check of students
  • Includes the ability to export data tables for Excel download, including an API to parse Excel content, using POI implementation

Later will be implemented: send email for verification when registering; Login is to remember the password and verification code verification; Rights management


Overall project structure:


Function display:

1. User login:

@RequestMapping(value = "/loginValidate",method = RequestMethod.POST)
    public String loginValidate(@RequestParam("username") String username,@RequestParam("password") String password,HttpSession httpSession) {
        if(username= =null || password= =null)
            return "user/login";
        else {
            User user = userService.getUserByUserName(username);
            if(user.getPassword().equals(password)) {
                httpSession.setAttribute("username", username);
                return "student/stuList";
            } else  {
                return "user/login"; }}}Copy the code
<select id="getUserByUserName" resultType="com.hlk.pojo.User" parameterType="string">
  
       
</select>Copy the code

2. User exit:

Click logout to return to the login page:

@RequestMapping(value = "/logout")
    public String logout(HttpSession httpSession) {
        httpSession.removeAttribute("username");
        return "redirect:/user/login";
    }Copy the code

3. System home page:

4, Add student:

5. Modify information:

Id cannot be changed. There are two common ways to do this:

  • disabled="true"Input elements are disabled. They cannot be edited, copied, selected, focused, or passed in the background. The color of the text becomes gray.
  • readonly="true"Selectable, you can receive focus, and you can select or copy its text. The background receives the passed value. The readonly property prevents the user from changing the value.

5. Paging function:

The foreground page gets the current number of pages and the number of pages displayed per page:

var grid = $("#grid-data").bootgrid({
            ajax:true,
            post: function (a)
            {
                return {
                    id: "b0df282a-0d67-40e5-8558-c9e93b7befed"
                };
            },
            url:"/stu/stuList",
            formatters: {
                "commands": function(column, row)
                {
                    return "<button type=\"button\" class=\"btn btn-xs btn-default command-edit\" data-row-id=\"" + row.stuId + "\" > edit < span class = \ "fa fa - pencil \" > < / span > < / button >" +
                        "<button type=\"button\" class=\"btn btn-xs btn-default command-delete\" data-row-id=\"" + row.stuId + Delete "/" > < span class = \ "fa fa - trash - o \" > < / span > < / button >";
                }
            }
        }).on("loaded.rs.jquery.bootgrid".function(a)
        {
            grid.find(".command-edit").on("click".function(e)
            {
                alert("You pressed edit on row: " + $(this).data("row-id"));
                $(".stumodal").modal();
                $.post("stu/getStuInfo",{id:$(this).data("row-id")},function(str){
                    alert("You pressed edit on row: " + $(this).data("row-id"));
                    var data=JSON.parse(str);
                    alert(data);
                    $("#sName").val(str.stuName);
                    $("#sAge").val(str.stuAge);
                    $("#sMajor").val(str.stuMajor);
                });
            }).end().find(".command-delete").on("click".function(e)
            {
                alert("You pressed delete on row: " + $(this).data("row-id"));
                $.post("/stu/delStu",{id:$(this).data("row-id")},function(a){
                    alert("Deleted successfully");
                    $("#grid-data").bootgrid("reload");
                });
            });
        });Copy the code
public class StuGrid {
    private int current;// The current page number
    private int rowCount;// Number of lines per page
    private int total;/ / the total number of rows
    privateList<Stu> rows; ** omit getter/setter**}Copy the code

Using Mybatis plugin pageHelper:

public List<Stu> getPageStu(int pagenum, int pagesize) {
     PageHelper.startPage(pagenum,pagesize);// Paging core code
     List<Stu> list = stuMapper.getStuList();
     return list;
 }Copy the code

Contorller control class:

 @RequestMapping(value = "/stuList",produces = {"application/json; charset=UTF-8"})
    @ResponseBody
    public StuGrid getStuList(@RequestParam("current") int current,@RequestParam("rowCount") int rowCount) {
        int total = stuService.getStuNum();
        List<Stu>  list = stuService.getPageStu(current,rowCount);
        StuGrid stuGrid = new StuGrid();
        stuGrid.setCurrent(current);
        stuGrid.setRowCount(rowCount);
        stuGrid.setRows(list);
        stuGrid.setTotal(total);
        return stuGrid;
    }Copy the code

6. Export data to generate Excel:

Get from database and write to Excel using POI:

 public InputStream getInputStream() throws Exception {
        String[] title=new String[]{"stuId"."stuName"."stuAge"."stuMajor"};
        List<Stu> plist=stuMapper.getStuList();
        List<Object[]>  dataList = new ArrayList<Object[]>();
        for(int i=0; i<plist.size(); i++){ Object[] obj=new Object[4];
            obj[0]=plist.get(i).getStuId();
            obj[1]=plist.get(i).getStuName();
            obj[2]=plist.get(i).getStuAge();
            obj[3]=plist.get(i).getStuMajor();
            dataList.add(obj);
        }
        WriteExcel ex = new WriteExcel(title, dataList);
        InputStream in;
        in = ex.export();
        return in;
    }Copy the code
@RequestMapping("/exportStu")
    public void export(HttpServletResponse response) throws Exception{
        InputStream is=stuService.getInputStream();
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("contentDisposition"."attachment; filename=AllUsers.xls");
        ServletOutputStream output = response.getOutputStream();
        IOUtils.copy(is,output);
    }Copy the code

Generated Excel table: