[CRM learning and development Day1 of SSM framework project customer relationship management system]

1.1 home page function

demand

When users visit the project home page, they first enter the login page.

Timing & flow

IndexController

@Controller
public class IndexController {
    /*
        Theoretically, assign a url to the Controller method: http://127.0.0.1:8080/crm/
        For simplicity, the protocol: / / ip:port / application name must be omitted, and / represents the application name under the application root directory/
     */
    @RequestMapping("/")
    public String index(){
        //Request forwarding
        return "index";
    }
}

UserController

@Controller
public class UserController {
    /**
     * url It should be consistent with the resource directory of the page returned by the response information after the controller method processes the request
     */
    @RequestMapping("/settings/qx/user/toLogin.do")
    public String toLogin(){
        //Forward request to login page
        return "settings/qx/user/login";
    }
}

1.2 user login

demand

On the login page, enter the user name and password, click the "login" button or enter to complete the user login function

* user name and password cannot be empty

* the user name or password is wrong, the user has expired, the user status is locked, and the ip is limited. You can't log in successfully

* after successful login, all business pages will display the name of the current user

* 10 days to remember password

* after successful login, jump to the business homepage

* login fails, the page does not jump, and the prompt message is displayed

Timing & flow

The difference between synchronous and asynchronous requests

Synchronization request: for the request sent by the browser window, the response information is returned to the browser window, so it will be refreshed globally.
Asynchronous request: the request sent by ajax, and the response information is returned to the ajax callback function, which can be refreshed globally or locally.

Summary: if global refresh is required, synchronous request or asynchronous request is recommended;
If local refresh is required, only asynchronous request can be used;
If global refresh or local refresh is possible, asynchronous request can only be used.

Transfer the processed data in the controller code to the view layer (jsp) and use scope transfer

pageContext: used to transfer data between different tags of the same page.
Request: pass data in the middle of the same request process.
session: transfer data between different requests of the same browser window. (remember password)
application: data shared by all users and used frequently for a long time.

Remember the password

Visit: login JSP --- > Background: html: if you remember the password last time, automatically fill in the account and password; Otherwise, do not fill in.
How to judge whether you remember the password last time? cookie
– if the last login is successful, judge whether you need to remember the password: if you need to remember the password, write a cookie to the browser; Otherwise, delete the cookie.
Moreover, the value of the cookie must be the loginAct and loginPwd of the user
– when logging in next time, judge whether the user has a cookie: if so, automatically fill in the account and password; Otherwise, don't write.
And the value of the cookie is filled in
----->Browser display

Get cookie:
1. Use java code to obtain cookie s:
Cookie[] cs=request.getCookies();
for(Cookie c:cs){
if(c.getName().equals("loginAct")){
String loginAct=c.getValue();
}else if(c.getName().equals("loginPwd")){
String loginPwd=c.getValue();
}
}
2. Use EL expression to obtain cookie:
${cookie.loginAct.value}
${cookie.loginPwd.value}

UserController

@Autowired
private UserService userService;

@RequestMapping("/settings/qx/user/login.do")
public @ResponseBody Object login(String loginAct, String loginPwd, String isRemPwd, HttpServletRequest request, HttpServletResponse response, HttpSession session) {
    //Packaging parameters
    Map<String,Object> map = new HashMap<>();
    map.put("loginAct",loginAct);
    map.put("loginPwd",loginPwd);

    //Call the service layer method to query the user
    User user = userService.queryUserByLoginActAndPwd(map);

    //Generate response information according to the query results
    ReturnObject returnObject = new ReturnObject();
    if (user == null) {
        //Login failed, wrong user name or password
        returnObject.setCode(Contants.RETURN_OBJECT_CODE_FAIL);
        returnObject.setMessage("Wrong user name or password");
    }else {//Further judge whether the account number is legal
        //user.getExpireTime()   //2019-10-20
        //        new Date()     //2020-09-10
        if (DateUtils.formateDateTime(new Date()).compareTo(user.getExpireTime()) > 0) {
            //Login failed, account expired
            returnObject.setCode(Contants.RETURN_OBJECT_CODE_FAIL);
            returnObject.setMessage("account has expired");
        } else if ("0".equals(user.getLockState())) {
            //Login failed, status locked
            returnObject.setCode(Contants.RETURN_OBJECT_CODE_FAIL);
            returnObject.setMessage("Status locked");
        } else if (!user.getAllowIps().contains(request.getRemoteAddr())) {
            //Login failed, ip restricted
            returnObject.setCode(Contants.RETURN_OBJECT_CODE_FAIL);
            returnObject.setMessage("ip be limited to");
        } else {
            //Login successful
            returnObject.setCode(Contants.RETURN_OBJECT_CODE_SUCCESS);

            //Add user to session
            session.setAttribute(Contants.SESSION_USER, user);

            Cookie c1=new Cookie("loginAct",user.getLoginAct());
            Cookie c2=new Cookie("loginPwd",user.getLoginPwd());
            if("true".equals(isRemPwd)){
                //If you need to remember the password, write the cookie out
                c1.setMaxAge(10*24*60*60);
                c2.setMaxAge(10*24*60*60);
            }else{
                //Delete cookie s that have not expired
                c1.setMaxAge(0);
                c2.setMaxAge(0);
            }
            response.addCookie(c1);
            response.addCookie(c2);
        }
    }
    return returnObject;
}

UserServiceImpl

@Autowired
private UserMapper userMapper;

@Override
public User queryUserByLoginActAndPwd(Map<String, Object> map) {
    return userMapper.selectUserByLoginActAndPwd(map);
}

mybatis reverse engineering

1) Introduction: generate mapper layer three parts of code according to the table: entity class, mapper interface and mapping file.
2) Reverse engineering using mybatis:
a) Create project: CRM mybatis generator
b) Add plug-in:

org. mybatis. Generator mybatis generator Maven plugin 1.3.2 true C) add the configuration file: the information of the directory table saved by the database connection information code d) run the reverse engineering of mybatis, generate java code according to the specified table and save it to the specified directory.

UserMapper

<select id="selectUserByLoginActAndPwd" parameterType="map" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from tbl_user
    where login_act=#{loginAct} and login_pwd=#{loginPwd}
</select>

Complete code

front end

index.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
	<script type="text/javascript">
		window.location.href = "settings/qx/user/toLogin.do";
	</script>
</body>
</html>

Use jquery to get the value of the specified attribute of the specified element

Selector attr("attribute name")// Used to get the value of attributes whose value is not true/false
Selector prop("attribute name")// Used to get the value of the property whose value is true/false For example, checked,selected,readonly,disabled, etc.

Usage of jquery event function

Selector click(function() {/ / add an event to the specified element
//js code
});

Selector click();// Simulates an event on the specified element

login.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/";
%>
<html>
<head>
	<base href="<%=basePath%>">
<meta charset="UTF-8">
<link href="jquery/bootstrap_3.3.0/css/bootstrap.min.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="jquery/jquery-1.11.1-min.js"></script>
<script type="text/javascript" src="jquery/bootstrap_3.3.0/js/bootstrap.min.js"></script>
<script type="text/javascript">
	$(function () {
		//Adds a keyboard press event to the entire browser window
		$(window).keydown(function (e) {
			//If the Enter key is pressed, the login request is submitted
			if(e.keyCode==13){
				$("#loginBtn").click();
			}
		});

		//Add a click event to the login button
		$("#loginBtn").click(function () {
			//Collect parameters
			var loginAct=$.trim($("#loginAct").val());
			var loginPwd=$.trim($("#loginPwd").val());
			var isRemPwd=$("#isRemPwd").prop("checked");
			//Form Validation 
			if (loginAct=="") {
				alert("User name cannot be empty");
				return;
			}
			if (loginPwd=="") {
				alert("Password cannot be empty");
				return;
			}
			//Show verifying
			// $("#msg").text("trying to verify...);
			//Send request
			$.ajax({
				url:'settings/qx/user/login.do',
				data:{
					loginAct:loginAct,
					loginPwd:loginPwd,
					isRemPwd:isRemPwd
				},
				type:'post',
				dataType:'json',
				success:function (data) {
					if (data.code=="1"){
						//Jump to business main page
						window.location.href="workbench/index.do";
					}else {
						//Prompt information
						$("#msg").text(data.message);
					}
				},
				beforeSend:function () {//This function will be executed automatically before ajax sends a request to the background;
					//The return value of this function can determine whether ajax actually sends a request to the background:
					//If the function returns true, ajax will actually send a request to the background; Otherwise, if the function returns false, ajax gives up sending the request to the background.
					$("#msg").text(" trying to verify... ");
					return true;
				}
			});
		});
	});
</script>
</head>
<body>
	<div style="position: absolute; top: 0px; left: 0px; width: 60%;">
		<img src="image/IMG_7114.JPG" style="width: 100%; height: 90%; position: relative; top: 50px;">
	</div>
	<div id="top" style="height: 50px; background-color: #3C3C3C; width: 100%;">
		<div style="position: absolute; top: 5px; left: 0px; font-size: 30px; font-weight: 400; color: white; font-family: 'times new roman'">CRM &nbsp;<span style="font-size: 12px;">&copy;2019&nbsp;Dynamic node</span></div>
	</div>
	
	<div style="position: absolute; top: 120px; right: 100px;width:450px;height:400px;border:1px solid #D5D5D5">
		<div style="position: absolute; top: 0px; right: 60px;">
			<div class="page-header">
				<h1>Sign in</h1>
			</div>
			<form action="workbench/index.html" class="form-horizontal" role="form">
				<div class="form-group form-group-lg">
					<div style="width: 350px;">
						<input class="form-control" id="loginAct" type="text" value="${cookie.loginAct.value}" placeholder="user name">
					</div>
					<div style="width: 350px; position: relative;top: 20px;">
						<input class="form-control" id="loginPwd" type="password" value="${cookie.loginPwd.value}" placeholder="password">
					</div>
					<div class="checkbox"  style="position: relative;top: 30px; left: 10px;">
						<label>
							<c:if test="${not empty cookie.loginAct and not empty cookie.loginPwd}">
								<input type="checkbox" id="isRemPwd" checked>
							</c:if>
							<c:if test="${empty cookie.loginAct or empty cookie.loginPwd}">
								<input type="checkbox" id="isRemPwd">
							</c:if>
							Login free within ten days
						</label>
						&nbsp;&nbsp;
						<span id="msg" style="color: red"></span>
					</div>
					<button type="button" id="loginBtn" class="btn btn-primary btn-lg btn-block"  style="width: 350px; position: relative;top: 45px;">Sign in</button>
				</div>
			</form>
		</div>
	</div>
</body>
</html>

back-end

IndexController

@Controller
public class IndexController {
    /*
        Theoretically, assign a url to the Controller method: http://127.0.0.1:8080/crm/
        For simplicity, the protocol: / / ip:port / application name must be omitted, and / represents the application name under the application root directory/
     */
    @RequestMapping("/")
    public String index(){
        //Request forwarding
        return "index";
    }
}

UserController

@Controller
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * url It should be consistent with the resource directory of the page returned by the response information after the controller method processes the request
     */
    @RequestMapping("/settings/qx/user/toLogin.do")
    public String toLogin(){
        //Forward request to login page
        return "settings/qx/user/login";
    }

    @RequestMapping("/settings/qx/user/login.do")
    public @ResponseBody Object login(String loginAct, String loginPwd, String isRemPwd, HttpServletRequest request, HttpServletResponse response, HttpSession session) {
        //Packaging parameters
        Map<String,Object> map = new HashMap<>();
        map.put("loginAct",loginAct);
        map.put("loginPwd",loginPwd);

        //Call the service layer method to query the user
        User user = userService.queryUserByLoginActAndPwd(map);

        //Generate response information according to the query results
        ReturnObject returnObject = new ReturnObject();
        if (user == null) {
            //Login failed, wrong user name or password
            returnObject.setCode(Contants.RETURN_OBJECT_CODE_FAIL);
            returnObject.setMessage("Wrong user name or password");
        }else {//Further judge whether the account number is legal
            //user.getExpireTime()   //2019-10-20
            //        new Date()     //2020-09-10
            if (DateUtils.formateDateTime(new Date()).compareTo(user.getExpireTime()) > 0) {
                //Login failed, account expired
                returnObject.setCode(Contants.RETURN_OBJECT_CODE_FAIL);
                returnObject.setMessage("account has expired");
            } else if ("0".equals(user.getLockState())) {
                //Login failed, status locked
                returnObject.setCode(Contants.RETURN_OBJECT_CODE_FAIL);
                returnObject.setMessage("Status locked");
            } else if (!user.getAllowIps().contains(request.getRemoteAddr())) {
                //Login failed, ip restricted
                returnObject.setCode(Contants.RETURN_OBJECT_CODE_FAIL);
                returnObject.setMessage("ip be limited to");
            } else {
                //Login successful
                returnObject.setCode(Contants.RETURN_OBJECT_CODE_SUCCESS);

                //Add user to session
                session.setAttribute(Contants.SESSION_USER, user);

                Cookie c1=new Cookie("loginAct",user.getLoginAct());
                Cookie c2=new Cookie("loginPwd",user.getLoginPwd());
                if("true".equals(isRemPwd)){
                    //If you need to remember the password, write the cookie out
                    c1.setMaxAge(10*24*60*60);
                    c2.setMaxAge(10*24*60*60);
                }else{
                    //Delete cookie s that have not expired
                    c1.setMaxAge(0);
                    c2.setMaxAge(0);
                }
                response.addCookie(c1);
                response.addCookie(c2);
            }
        }
        return returnObject;
    }
}

UserService

public interface UserService {
    User queryUserByLoginActAndPwd(Map<String, Object> map);
}

UserServiceImpl

@Service("userService")
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User queryUserByLoginActAndPwd(Map<String, Object> map) {
        return userMapper.selectUserByLoginActAndPwd(map);
    }
}

User entity class

public class User {
    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tbl_user.id
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    private String id;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tbl_user.login_act
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    private String loginAct;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tbl_user.name
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    private String name;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tbl_user.login_pwd
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    private String loginPwd;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tbl_user.email
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    private String email;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tbl_user.expire_time
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    private String expireTime;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tbl_user.lock_state
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    private String lockState;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tbl_user.deptno
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    private String deptno;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tbl_user.allow_ips
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    private String allowIps;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tbl_user.createTime
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    private String createtime;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tbl_user.create_by
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    private String createBy;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tbl_user.edit_time
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    private String editTime;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tbl_user.edit_by
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    private String editBy;

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tbl_user.id
     *
     * @return the value of tbl_user.id
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    public String getId() {
        return id;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column tbl_user.id
     *
     * @param id the value for tbl_user.id
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    public void setId(String id) {
        this.id = id == null ? null : id.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tbl_user.login_act
     *
     * @return the value of tbl_user.login_act
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    public String getLoginAct() {
        return loginAct;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column tbl_user.login_act
     *
     * @param loginAct the value for tbl_user.login_act
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    public void setLoginAct(String loginAct) {
        this.loginAct = loginAct == null ? null : loginAct.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tbl_user.name
     *
     * @return the value of tbl_user.name
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    public String getName() {
        return name;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column tbl_user.name
     *
     * @param name the value for tbl_user.name
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    public void setName(String name) {
        this.name = name == null ? null : name.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tbl_user.login_pwd
     *
     * @return the value of tbl_user.login_pwd
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    public String getLoginPwd() {
        return loginPwd;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column tbl_user.login_pwd
     *
     * @param loginPwd the value for tbl_user.login_pwd
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    public void setLoginPwd(String loginPwd) {
        this.loginPwd = loginPwd == null ? null : loginPwd.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tbl_user.email
     *
     * @return the value of tbl_user.email
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    public String getEmail() {
        return email;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column tbl_user.email
     *
     * @param email the value for tbl_user.email
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    public void setEmail(String email) {
        this.email = email == null ? null : email.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tbl_user.expire_time
     *
     * @return the value of tbl_user.expire_time
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    public String getExpireTime() {
        return expireTime;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column tbl_user.expire_time
     *
     * @param expireTime the value for tbl_user.expire_time
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    public void setExpireTime(String expireTime) {
        this.expireTime = expireTime == null ? null : expireTime.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tbl_user.lock_state
     *
     * @return the value of tbl_user.lock_state
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    public String getLockState() {
        return lockState;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column tbl_user.lock_state
     *
     * @param lockState the value for tbl_user.lock_state
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    public void setLockState(String lockState) {
        this.lockState = lockState == null ? null : lockState.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tbl_user.deptno
     *
     * @return the value of tbl_user.deptno
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    public String getDeptno() {
        return deptno;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column tbl_user.deptno
     *
     * @param deptno the value for tbl_user.deptno
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    public void setDeptno(String deptno) {
        this.deptno = deptno == null ? null : deptno.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tbl_user.allow_ips
     *
     * @return the value of tbl_user.allow_ips
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    public String getAllowIps() {
        return allowIps;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column tbl_user.allow_ips
     *
     * @param allowIps the value for tbl_user.allow_ips
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    public void setAllowIps(String allowIps) {
        this.allowIps = allowIps == null ? null : allowIps.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tbl_user.createTime
     *
     * @return the value of tbl_user.createTime
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    public String getCreatetime() {
        return createtime;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column tbl_user.createTime
     *
     * @param createtime the value for tbl_user.createTime
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    public void setCreatetime(String createtime) {
        this.createtime = createtime == null ? null : createtime.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tbl_user.create_by
     *
     * @return the value of tbl_user.create_by
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    public String getCreateBy() {
        return createBy;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column tbl_user.create_by
     *
     * @param createBy the value for tbl_user.create_by
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    public void setCreateBy(String createBy) {
        this.createBy = createBy == null ? null : createBy.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tbl_user.edit_time
     *
     * @return the value of tbl_user.edit_time
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    public String getEditTime() {
        return editTime;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column tbl_user.edit_time
     *
     * @param editTime the value for tbl_user.edit_time
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    public void setEditTime(String editTime) {
        this.editTime = editTime == null ? null : editTime.trim();
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tbl_user.edit_by
     *
     * @return the value of tbl_user.edit_by
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    public String getEditBy() {
        return editBy;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method sets the value of the database column tbl_user.edit_by
     *
     * @param editBy the value for tbl_user.edit_by
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    public void setEditBy(String editBy) {
        this.editBy = editBy == null ? null : editBy.trim();
    }
}

UserMapper mapper interface

public interface UserMapper {
    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_user
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    int deleteByPrimaryKey(String id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_user
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    int insert(User record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_user
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    int insertSelective(User record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_user
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    User selectByPrimaryKey(String id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_user
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    int updateByPrimaryKeySelective(User record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tbl_user
     *
     * @mbggenerated Tue May 24 10:39:00 CST 2022
     */
    int updateByPrimaryKey(User record);

    /**
     * Query users according to account and password
     * @param map
     * @return
     */
    User selectUserByLoginActAndPwd(Map<String,Object> map);
}

UserMapper.xml Mapping File

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.yyp.crm.settings.mapper.UserMapper" >
  <resultMap id="BaseResultMap" type="com.yyp.crm.settings.domain.User" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue May 24 10:39:00 CST 2022.
    -->
    <id column="id" property="id" jdbcType="CHAR" />
    <result column="login_act" property="loginAct" jdbcType="VARCHAR" />
    <result column="name" property="name" jdbcType="VARCHAR" />
    <result column="login_pwd" property="loginPwd" jdbcType="VARCHAR" />
    <result column="email" property="email" jdbcType="VARCHAR" />
    <result column="expire_time" property="expireTime" jdbcType="CHAR" />
    <result column="lock_state" property="lockState" jdbcType="CHAR" />
    <result column="deptno" property="deptno" jdbcType="CHAR" />
    <result column="allow_ips" property="allowIps" jdbcType="VARCHAR" />
    <result column="createTime" property="createtime" jdbcType="CHAR" />
    <result column="create_by" property="createBy" jdbcType="VARCHAR" />
    <result column="edit_time" property="editTime" jdbcType="CHAR" />
    <result column="edit_by" property="editBy" jdbcType="VARCHAR" />
  </resultMap>
  <sql id="Base_Column_List" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue May 24 10:39:00 CST 2022.
    -->
    id, login_act, name, login_pwd, email, expire_time, lock_state, deptno, allow_ips, 
    createTime, create_by, edit_time, edit_by
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue May 24 10:39:00 CST 2022.
    -->
    select 
    <include refid="Base_Column_List" />
    from tbl_user
    where id = #{id,jdbcType=CHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue May 24 10:39:00 CST 2022.
    -->
    delete from tbl_user
    where id = #{id,jdbcType=CHAR}
  </delete>
  <insert id="insert" parameterType="com.yyp.crm.settings.domain.User" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue May 24 10:39:00 CST 2022.
    -->
    insert into tbl_user (id, login_act, name, 
      login_pwd, email, expire_time, 
      lock_state, deptno, allow_ips, 
      createTime, create_by, edit_time, 
      edit_by)
    values (#{id,jdbcType=CHAR}, #{loginAct,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, 
      #{loginPwd,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{expireTime,jdbcType=CHAR}, 
      #{lockState,jdbcType=CHAR}, #{deptno,jdbcType=CHAR}, #{allowIps,jdbcType=VARCHAR}, 
      #{createtime,jdbcType=CHAR}, #{createBy,jdbcType=VARCHAR}, #{editTime,jdbcType=CHAR}, 
      #{editBy,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.yyp.crm.settings.domain.User" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue May 24 10:39:00 CST 2022.
    -->
    insert into tbl_user
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="loginAct != null" >
        login_act,
      </if>
      <if test="name != null" >
        name,
      </if>
      <if test="loginPwd != null" >
        login_pwd,
      </if>
      <if test="email != null" >
        email,
      </if>
      <if test="expireTime != null" >
        expire_time,
      </if>
      <if test="lockState != null" >
        lock_state,
      </if>
      <if test="deptno != null" >
        deptno,
      </if>
      <if test="allowIps != null" >
        allow_ips,
      </if>
      <if test="createtime != null" >
        createTime,
      </if>
      <if test="createBy != null" >
        create_by,
      </if>
      <if test="editTime != null" >
        edit_time,
      </if>
      <if test="editBy != null" >
        edit_by,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=CHAR},
      </if>
      <if test="loginAct != null" >
        #{loginAct,jdbcType=VARCHAR},
      </if>
      <if test="name != null" >
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="loginPwd != null" >
        #{loginPwd,jdbcType=VARCHAR},
      </if>
      <if test="email != null" >
        #{email,jdbcType=VARCHAR},
      </if>
      <if test="expireTime != null" >
        #{expireTime,jdbcType=CHAR},
      </if>
      <if test="lockState != null" >
        #{lockState,jdbcType=CHAR},
      </if>
      <if test="deptno != null" >
        #{deptno,jdbcType=CHAR},
      </if>
      <if test="allowIps != null" >
        #{allowIps,jdbcType=VARCHAR},
      </if>
      <if test="createtime != null" >
        #{createtime,jdbcType=CHAR},
      </if>
      <if test="createBy != null" >
        #{createBy,jdbcType=VARCHAR},
      </if>
      <if test="editTime != null" >
        #{editTime,jdbcType=CHAR},
      </if>
      <if test="editBy != null" >
        #{editBy,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.yyp.crm.settings.domain.User" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue May 24 10:39:00 CST 2022.
    -->
    update tbl_user
    <set >
      <if test="loginAct != null" >
        login_act = #{loginAct,jdbcType=VARCHAR},
      </if>
      <if test="name != null" >
        name = #{name,jdbcType=VARCHAR},
      </if>
      <if test="loginPwd != null" >
        login_pwd = #{loginPwd,jdbcType=VARCHAR},
      </if>
      <if test="email != null" >
        email = #{email,jdbcType=VARCHAR},
      </if>
      <if test="expireTime != null" >
        expire_time = #{expireTime,jdbcType=CHAR},
      </if>
      <if test="lockState != null" >
        lock_state = #{lockState,jdbcType=CHAR},
      </if>
      <if test="deptno != null" >
        deptno = #{deptno,jdbcType=CHAR},
      </if>
      <if test="allowIps != null" >
        allow_ips = #{allowIps,jdbcType=VARCHAR},
      </if>
      <if test="createtime != null" >
        createTime = #{createtime,jdbcType=CHAR},
      </if>
      <if test="createBy != null" >
        create_by = #{createBy,jdbcType=VARCHAR},
      </if>
      <if test="editTime != null" >
        edit_time = #{editTime,jdbcType=CHAR},
      </if>
      <if test="editBy != null" >
        edit_by = #{editBy,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=CHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.yyp.crm.settings.domain.User" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue May 24 10:39:00 CST 2022.
    -->
    update tbl_user
    set login_act = #{loginAct,jdbcType=VARCHAR},
      name = #{name,jdbcType=VARCHAR},
      login_pwd = #{loginPwd,jdbcType=VARCHAR},
      email = #{email,jdbcType=VARCHAR},
      expire_time = #{expireTime,jdbcType=CHAR},
      lock_state = #{lockState,jdbcType=CHAR},
      deptno = #{deptno,jdbcType=CHAR},
      allow_ips = #{allowIps,jdbcType=VARCHAR},
      createTime = #{createtime,jdbcType=CHAR},
      create_by = #{createBy,jdbcType=VARCHAR},
      edit_time = #{editTime,jdbcType=CHAR},
      edit_by = #{editBy,jdbcType=VARCHAR}
    where id = #{id,jdbcType=CHAR}
  </update>

  <select id="selectUserByLoginActAndPwd" parameterType="map" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from tbl_user
    where login_act=#{loginAct} and login_pwd=#{loginPwd}
  </select>

</mapper>

Tags: Java Front-end Database Spring Spring Boot

Posted by goldfiles on Wed, 25 May 2022 00:07:31 +0300