Spring boot entry five spring mvc spring boot mybatis configuration integration

Spring boot entry five spring mvc spring boot mybatis configuration integration

Everyone has a basic understanding of Spring Boot, but Spring Boot is just a box that encapsulates and integrates references. It needs to be combined with specific projects to be truly used.

It is mainly to record the integration of Spring Mvc and mybatis using Spring Boot:

The specific configuration is as follows:

1. Create a Maven project, which can be a web project or a basic maven project,

2. Configure pom.xml

3. Configure the properties file

Create application.properties in the resources directory

#Data Source Driven

4. Configure Mybatis

1), create a Mapper interface file

2), create mapper.xml

Create a mapper directory under the resources directory and create UserMapper.xml

/mapper/UserMapper.xml

3), create entity class

4. Configure the Controller class UserController

5. Configure the database processing class

Database creation script:

6. Write a test for the public class returned by jason

package com.sam.project.mvc.common;

/**

* @ClassName : AjaxResult

* @Description: Encapsulate return data

*/

public class AjaxResult {

private int retcode = 1;

private String retmsg = "Operation successful";

private Object data;

public AjaxResult(int retcode, String retmsg, Object data){

this.retcode = retcode;

this.retmsg = retmsg;

this.data = data;

}

public AjaxResult(int retcode, String retmsg){

this.retcode = retcode;

this.retmsg = retmsg;

}

public AjaxResult(Object data){

this.retmsg = "Query successful";

this.data = data;

}

public AjaxResult(int retcode){

this.retcode = retcode;

this.retmsg = "The operation failed";

}

public AjaxResult(String retmsg){

this.retcode = 0;

this.retmsg = retmsg;

}

public AjaxResult(){

}

public int getRetcode() {

return retcode;

}

public void setRetcode(int retcode) {

this.retcode = retcode;

}

public String getRetmsg() {

return retmsg;

}

public void setRetmsg(String retmsg) {

this.retmsg = retmsg;

}

public Object getData() {

return data;

}

public void setData(Object data) {

this.data = data;

}

@Override

public String toString() {

return "AjaxResult [retcode=" + retcode + ", retmsg=" + retmsg + ", data=" + data + "]";

}

}

7. Create a startup entry:

Well, at this point, the configuration is complete, and the directory after creation is as follows:

Start the Main method of the Application class to start Spring Boot