SSM library management system (enhanced version, with source code)

The original function of the system (newcomers must read) :

1. The system is divided into three user roles: ordinary user, administrator, and superstar administrator, corresponding to users, admins, and sysadmin database tables

 

b4a381e280afacf7e8137c9619c172f8.png

2. Basic functions of ordinary users: query books, borrow books, return books

e0ad76c32d792bb54c9e2616cd7cf823.png

 

3. Basic functions of the administrator: borrowing books, returning books

27295dc3b6847a1b47bd5748d578b41a.png

 

4. Super administrator functions: common user management, book management, category management

98d49aa4db8609d306a72422d44b8268.png


 

The above is to share with you the source code of the SSM library management system project, which is very popular, but I also found that the functions are not very comprehensive, so this time the system has been enhanced. The following are some aspects of the system changes

31641add5a8908efefa6afac23bb6fc2.png

1. Database changes

  • The users table adds two fields: major (professional), gender (gender)

  • A field is added to the books table: times (number of books borrowed)

  • Added the log table, which is the log table

If you have already built a previous project, it is recommended that you re-create a database named librarydb to avoid conflicts with the previous database

2. On the normal user page, the personal center menu has been added

Personal center, which displays the basic information of the current user, such as user name, password, gender and other attributes, which can also be edited

02c19f1d73feb13b5ff64f5b6e6c636e.png

3. Added log management and chart analysis menus on the super administrator page

Log management, all roles will be recorded after logging in to the system. The log records the user name, user role, browser type, user IP, and login time.
After downloading the project folder, you will find that there are more util packages than before. The BrowserUtil and IpUtil under this package are tools for obtaining the browser type and IP. In terms of query, you can accurately query according to the user
name

3db84d1f2b28c678774f84be35e88d3d.png

Chart analysis, based on the classification of books, counting the number of books under each classification, using Echats technology, the functional effect is as shown in the figure

d53bc8b1f1a72184fe13c417fa63f772.png

Echarts official website: https://echarts.apache.org/zh/index.html

13fb09525b1222cb8b2928c5d3d233f5.png

About modification

Of course, if you only add one of the above functions first, you can find the code of the corresponding page and change the menu you want to display. Let’s take the sysadmin/index.jsp file corresponding to the super administrator menu as an example:

<script>
    BUI.use('common/main',function(){
        var config = [
        {id:'1',menu:[
                {text:'系统管理',items:[
                    {id:'3',text:'用户管理',href:'<%=request.getContextPath()%>/sysadmin/showUser'},
                    {id:'12',text:'书籍管理',href:'<%=request.getContextPath()%>/sysadmin/show'},
                    {id:'13',text:'类别管理',href:'<%=request.getContextPath()%>/sort/findAll'},
                    {id:'14',text:'登录日志',href:'<%=request.getContextPath()%>/sysadmin/log'}
                   ]
                },
                {
                    text: '图表管理', items: [
                        {id: '15', text: '图表分析', href: '<%=request.getContextPath()%>/sysadmin/chart'},
                    ]
                }
            ]
        },

    ];
        new PageUtil.MainPage({
            modulesConfig : config
        });
    });
</script>


 

core code

Log entity class:

package com.xian.pojo;

import com.fasterxml.jackson.annotation.JsonFormat;

import java.sql.Timestamp;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;

//登录日志实体类
public class Log {
    private Integer id;
    private String code;
    private String role;
    private String browser;
    private Timestamp datetime;
    private String ip;
    // 页面数据
    private int start;
    // 当前页数
    private int currentPage;
    public Log() {}

    public Log(Integer id, String code, String role, String browser, Timestamp datetime, String ip) {
        this.id = id;
        this.code = code;
        this.role = role;
        this.browser = browser;
        this.datetime = datetime;
        this.ip = ip;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getRole() {
        return role;
    }

    public void setRole(String role) {
        this.role = role;
    }

    public String getBrowser() {
        return browser;
    }

    public void setBrowser(String browser) {
        this.browser = browser;
    }

    public Date getDatetime() {
        return datetime;
    }

    public void setDatetime(Timestamp datetime) {
        this.datetime = datetime;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public int getStart() {
        return start;
    }

    public void setStart(int start) {
        this.start = start;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    @Override
    public String toString() {
        return "Log{" +
                "id=" + id +
                ", code='" + code + '\'' +
                ", role='" + role + '\'' +
                ", browser='" + browser + '\'' +
                ", datetime=" + datetime +
                ", ip='" + ip + '\'' +
                '}';
    }
}

The control layer PageController, when requesting /login, and the user successfully logs in, will call the redcord method of LogService to save the login log to the database

package com.xian.controller;

@Controller
public class PageController {
	@Autowired
	private BooksService bookService;

	@Autowired
	private AdminService adminService;

	@Autowired
	private SysAdminService sysAdminService;

	@Autowired
	private SortService sortService;

	@Autowired
	private LogService logService;

	@RequestMapping("/index")
	public String toIndex() {
		return "login";
	}

	@RequestMapping("/login")
	public String login(Users user, int loginType, Model model, HttpServletRequest request, HttpSession session) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Timestamp timestamp = null;
		try {
			Date date = sdf.parse(sdf.format(new Date()));
			timestamp = new Timestamp(date.getTime());
		}catch (Exception e){
			e.printStackTrace();
		}
		// 普通用户
		if (loginType == 1) {
			Users users = bookService.selectUser(user);
			if (users != null) {
				logService.record(new Log(null,user.getCode(),"普通用户", BrowserUtil.getBrower(request),timestamp, IpUtil.getIpAddr(request)));
				session.setAttribute("user", users);
				return "redirect:/user/index";
			} else {
				model.addAttribute("msg", "账号或密码错误");
				return "login";
			}
		} else if (loginType == 2) {
			Admin admin = adminService.getAdmin(user);
			if (admin != null) {
				session.setAttribute("admin", admin);
				logService.record(new Log(null,admin.getCode(),"管理员", BrowserUtil.getBrower(request), timestamp, IpUtil.getIpAddr(request)));
				return "redirect:/admin/index";
			} else {
				model.addAttribute("msg", "账号或密码错误");
				return "login";
			}
		} else if (loginType == 3) {
			SysAdmin sysAdmin = sysAdminService.getSysAdmin(user);
			if (sysAdmin != null) {
				session.setAttribute("sysAdmin", sysAdmin);
				logService.record(new Log(null,sysAdmin.getCode(),"超级管理员", BrowserUtil.getBrower(request),timestamp, IpUtil.getIpAddr(request)));
				return "redirect:/sysadmin/index";
			} else {
				model.addAttribute("msg", "账号或密码错误");
				return "login";
			}
		}
		return "login";
	}

}

 

How to get the source code?

Enter the "Yima" Xiaocheng sequence, and you can get it by viewing the SSM source code category

 

 

 

Guess you like

Origin blog.csdn.net/calm_programmer/article/details/128449915