SpringBoot integrates SpringMVC, persistence layer technology MyBatis

1. Implement an operation of adding, modifying, deleting and querying data tables in the database by integrating SpringBoot, SpringMVC and MyBatis.

First of all, you're using the Springboot version 2.2.6.RELEASE, and since Springboot iterates quickly, you need to be aware of the version issues.

Add a new dependency package to the pom file as follows:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 3          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
 4     <modelVersion>4.0.0</modelVersion>
 5     <parent>
 6         <groupId>org.springframework.boot</groupId>
 7         <artifactId>spring-boot-starter-parent</artifactId>
 8         <version>2.2.6.RELEASE</version>
 9         <relativePath/> <!-- lookup parent from repository -->
10     </parent>
11     <groupId>com.bie</groupId>
12     <artifactId>springboot-hello</artifactId>
13     <version>0.0.1-SNAPSHOT</version>
14     <name>springboot-hello</name>
15     <description>Demo project for Spring Boot</description>
16 
17     <properties>
18         <java.version>1.8</java.version>
19     </properties>
20 
21     <dependencies>
22         <dependency>
23             <groupId>org.springframework.boot</groupId>
24             <artifactId>spring-boot-starter-web</artifactId>
25         </dependency>
26         <dependency>
27             <groupId>org.springframework.boot</groupId>
28             <artifactId>spring-boot-starter-test</artifactId>
29             <scope>test</scope>
30             <exclusions>
31                 <exclusion>
32                     <groupId>org.junit.vintage</groupId>
33                     <artifactId>junit-vintage-engine</artifactId>
34                 </exclusion>
35             </exclusions>
36         </dependency>
37         <!-- thymeleaf Launcher -->
38         <dependency>
39             <groupId>org.springframework.boot</groupId>
40             <artifactId>spring-boot-starter-thymeleaf</artifactId>
41         </dependency>
42         <!-- mybatis Launcher -->
43         <dependency>
44             <groupId>org.mybatis.spring.boot</groupId>
45             <artifactId>mybatis-spring-boot-starter</artifactId>
46             <version>2.1.1</version>
47         </dependency>
48         <!-- mysql Database Driven Dependent Packages -->
49         <dependency>
50             <groupId>mysql</groupId>
51             <artifactId>mysql-connector-java</artifactId>
52         </dependency>
53         <!-- druid Database Connection Pool -->
54         <dependency>
55             <groupId>com.alibaba</groupId>
56             <artifactId>druid</artifactId>
57             <version>1.1.10</version>
58         </dependency>
59     </dependencies>
60 
61     <build>
62         <plugins>
63             <plugin>
64                 <groupId>org.springframework.boot</groupId>
65                 <artifactId>spring-boot-maven-plugin</artifactId>
66             </plugin>
67         </plugins>
68     </build>
69 
70 </project>

Configure the application.properties global configuration file.

 1 # Configure port number 8080, default is 8080
 2 server.port=8080
 3 server.address=127.0.0.1
 4 
 5 # Database Driver,Springboot2.2.6.RELEASE Edition
 6 spring.datasource.driver-class-name=com.mysql.jdbc.Driver
 7 # Database Links URL,Springboot2.2.6.RELEASE Edition
 8 spring.datasource.url=jdbc:mysql://localhost:3306/biehl
 9 # Database Account,Springboot2.2.6.RELEASE Edition
10 spring.datasource.username=root
11 # Database Password,Springboot2.2.6.RELEASE Edition
12 spring.datasource.password=123456
13 
14 # Configure druid database connection pool, data source type
15 spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
16 
17 # Configure mybatis to access the alias of the entity class
18 mybatis.type-aliases-package=com.bie.springboothello.po

Database table design, simply create a user data table.

 1 /*
 2  Navicat Premium Data Transfer
 3 
 4  Source Server         : localhost
 5  Source Server Type    : MySQL
 6  Source Server Version : 50724
 7  Source Host           : localhost:3306
 8  Source Schema         : biehl
 9 
10  Target Server Type    : MySQL
11  Target Server Version : 50724
12  File Encoding         : 65001
13 
14  Date: 11/05/2020 12:13:21
15 */
16 
17 SET NAMES utf8mb4;
18 SET FOREIGN_KEY_CHECKS = 0;
19 
20 -- ----------------------------
21 -- Table structure for users
22 -- ----------------------------
23 DROP TABLE IF EXISTS `users`;
24 CREATE TABLE `users`  (
25   `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'User Number',
26   `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT 'User Account',
27   `age` int(11) DEFAULT NULL COMMENT 'User Age',
28   PRIMARY KEY (`id`) USING BTREE
29 ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = 'User table' ROW_FORMAT = Dynamic;
30 
31 SET FOREIGN_KEY_CHECKS = 1;

Create entity class Users.

 1 package com.bie.springboothello.po;
 2 
 3 public class Users {
 4 
 5     private int id;
 6     private String name;
 7     private int age;
 8 
 9     public int getId() {
10         return id;
11     }
12 
13     public void setId(int id) {
14         this.id = id;
15     }
16 
17     public String getName() {
18         return name;
19     }
20 
21     public void setName(String name) {
22         this.name = name;
23     }
24 
25     public int getAge() {
26         return age;
27     }
28 
29     public void setAge(int age) {
30         this.age = age;
31     }
32 
33     @Override
34     public String toString() {
35         return "Users{" +
36                 "id=" + id +
37                 ", name='" + name + '\'' +
38                 ", age=" + age +
39                 '}';
40     }
41 
42     public Users(int id, String name, int age) {
43         this.id = id;
44         this.name = name;
45         this.age = age;
46     }
47 }

Create a mapper interface and a mapping configuration file.

 1 package com.bie.springboothello.mapper;
 2 
 3 import com.bie.springboothello.po.Users;
 4 import org.springframework.stereotype.Repository;
 5 
 6 import java.util.List;
 7 
 8 /**
 9  *
10  */
11 @Repository // Inside the boot class, if it is on@MapperScan Notes.
12 public interface UsersMapper {
13 
14     /**
15      * Insert User Information
16      *
17      * @param users
18      */
19     public void insertUser(Users users);
20 
21     /**
22      * Query all user information
23      *
24      * @return
25      */
26     public List<Users> selectUsersAll();
27 
28     /**
29      * Query based on user number
30      *
31      * @param id
32      * @return
33      */
34     public Users selectUsersById(Integer id);
35 
36 
37     /**
38      * Modify user information
39      *
40      * @param users
41      */
42     public void updateUser(Users users);
43 
44     /**
45      * Delete based on user number
46      *
47      * @param id
48      */
49     public void deleteUserById(Integer id);
50 }

Map the configuration file, as shown below, and the problems are described later.

 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 <!DOCTYPE mapper
 3         PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 4         "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 5 <! -- The value of namespace must be the same as the interface name of apper-->
 6 <mapper namespace="com.bie.springboothello.mapper.UsersMapper">
 7 
 8 <! -- ID must be the same as the method name inside the UsersMapper interface -->
 9 <!--Since mybatis.type-aliases-package alias is configured in application.properties, use entity class name directly here-->
10 
11 <!--Insert User Information-->
12     <insert id="insertUser" parameterType="users">
13         insert into users(name,age) values(#{name},#{age})
14     </insert>
15 
16 <!--Query all user information-->
17     <select id="selectUsersAll" resultType="users">
18         select id,name,age from users
19     </select>
20 
21 <!--Query by user number-->
22     <select id="selectUsersById" resultType="users">
23         select id,name,age from users where id = #{value}
24     </select>
25 
26 <!--Modify user information-->
27     <update id="updateUser" parameterType="users">
28         update users set name=#{name} ,age=#{age} where id=#{id}
29     </update>
30 
31 <!--Delete by user number-->
32     <delete id="deleteUserById">
33         delete from users where id = #{value}
34     </delete>
35 </mapper>

Create business-tier interfaces and business-tier interface implementation classes.

 1 package com.bie.springboothello.service;
 2 
 3 import com.bie.springboothello.po.Users;
 4 
 5 import java.util.List;
 6 
 7 /**
 8  *
 9  */
10 public interface UsersService {
11 
12     /**
13      * Insert User Information
14      *
15      * @param users
16      */
17     public void addUser(Users users);
18 
19     /**
20      * Query all user information
21      *
22      * @return
23      */
24     public List<Users> findUserAll();
25 
26     /**
27      * Query based on user number
28      *
29      * @param id
30      * @return
31      */
32     public Users findUserById(Integer id);
33 
34     /**
35      * Modify user information
36      *
37      * @param users
38      */
39     public void updateUser(Users users);
40 
41     /**
42      * Delete based on user number
43      *
44      * @param id
45      */
46     public void deleteUserById(Integer id);
47 }

Business layer interface implementation class.

 1 package com.bie.springboothello.service.impl;
 2 
 3 import com.bie.springboothello.mapper.UsersMapper;
 4 import com.bie.springboothello.po.Users;
 5 import com.bie.springboothello.service.UsersService;
 6 import org.springframework.beans.factory.annotation.Autowired;
 7 import org.springframework.stereotype.Service;
 8 import org.springframework.transaction.annotation.Transactional;
 9 
10 import java.util.List;
11 
12 @Service // Injection into Spring Of bean In container
13 @Transactional // Open Transaction,All methods under this class are transactionally controlled
14 public class UsersServiceImpl implements UsersService {
15 
16     @Autowired // Dependent Injection
17     private UsersMapper usersMapper;
18 
19     @Override
20     public void addUser(Users users) {
21         this.usersMapper.insertUser(users);
22     }
23 
24     @Override
25     public List<Users> findUserAll() {
26         return this.usersMapper.selectUsersAll();
27     }
28 
29     @Override
30     public Users findUserById(Integer id) {
31         return this.usersMapper.selectUsersById(id);
32     }
33 
34     @Override
35     public void updateUser(Users users) {
36         this.usersMapper.updateUser(users);
37     }
38 
39     @Override
40     public void deleteUserById(Integer id) {
41         this.usersMapper.deleteUserById(id);
42     }
43 
44 }

Create a control layer.

  1 package com.bie.springboothello.controller;
  2 
  3 import com.bie.springboothello.po.Users;
  4 import com.bie.springboothello.service.UsersService;
  5 import org.springframework.beans.factory.annotation.Autowired;
  6 import org.springframework.stereotype.Controller;
  7 import org.springframework.ui.Model;
  8 import org.springframework.web.bind.annotation.PathVariable;
  9 import org.springframework.web.bind.annotation.RequestMapping;
 10 import org.springframework.web.bind.annotation.ResponseBody;
 11 
 12 import java.util.List;
 13 
 14 @Controller
 15 @RequestMapping(value = "/users")
 16 public class UsersController {
 17 
 18     @Autowired
 19     private UsersService usersService;
 20 
 21     @RequestMapping(value = "/hello")
 22     @ResponseBody
 23     public String showUser(Model model) {
 24         return "hello";
 25     }
 26 
 27     /**
 28      * Page Jump
 29      * <p>
 30      * <p>
 31      * thymeleaf Framework, a template-level view-layer technology, needs to be placed in the root directory of the classpath, under a package called templates under src/main/resources
 32      *
 33      * <p>
 34      * <p>
 35      * Since the templates directory is secure and cannot be accessed directly from the outside world, there must be a method inside the Controller to place the view inside it
 36      * Help make page jumps, the purpose of this method is to make page jumps.
 37      *
 38      * @param page
 39      * @return
 40      */
 41     @RequestMapping(value = "/{page}")
 42     public String showPage(@PathVariable String page) {
 43         System.out.println("============================================" + page);
 44         return page;
 45     }
 46 
 47     /**
 48      * Add user information
 49      *
 50      * @param users
 51      * @return
 52      */
 53     @RequestMapping(value = "addUser")
 54     public String addUser(Users users) {
 55         this.usersService.addUser(users);
 56         return "redirect:/users/findUserAll";
 57     }
 58 
 59     /**
 60      * Query all users
 61      *
 62      * @param model
 63      * @return
 64      */
 65     @RequestMapping(value = "findUserAll")
 66     public String findUserAll(Model model) {
 67         List<Users> list = this.usersService.findUserAll();
 68         model.addAttribute("list", list);
 69         return "showUsers";
 70     }
 71 
 72     /**
 73      * Query user information based on user id
 74      *
 75      * @param id
 76      * @param model
 77      * @return
 78      */
 79     @RequestMapping(value = "findUserById")
 80     public String findUserById(Integer id, Model model) {
 81         Users user = this.usersService.findUserById(id);
 82         model.addAttribute("user", user);
 83         return "updateUser";
 84     }
 85 
 86     /**
 87      * Update user information
 88      *
 89      * @param users
 90      * @return
 91      */
 92     @RequestMapping(value = "editUser")
 93     public String editUser(Users users) {
 94         this.usersService.updateUser(users);
 95         return "redirect:/users/findUserAll";
 96     }
 97 
 98     @RequestMapping(value = "delUser")
 99     public String delUser(Integer id) {
100         this.usersService.deleteUserById(id);
101         return "redirect:/users/findUserAll";
102 
103     }
104 }

Create several pages as follows:

 1 <!DOCTYPE html>
 2 <html xmlns:th="http://www.w3.org/1999/xhtml">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>Show user data</title>
 6 
 7     <!-- Latest version of Bootstrap core CSS file -->
 8     <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css">
 9     <!-- Abreast of the times Bootstrap core JavaScript file -->
10     <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
11     <style>
12         tr th {
13             text-align: center;
14         }
15 
16         tr td {
17             text-align: center;
18         }
19 
20         h1 {
21             text-align: center;
22         }
23     </style>
24 </head>
25 <body>
26 
27 <h1>User List</h1>
28 <br/>
29 <hr/>
30 <br/><br/>
31 
32 <div class="row">
33     <div class="col-md-2"></div>
34     <div class="col-md-8">
35         <div style="text-align: left;padding-left:900px;">
36             <a th:href="@{/users/input}" class="btn btn-success">New Users</a>
37         </div>
38         <br/>
39         <table class="table table-striped table-hover table-condensed">
40             <tr>
41                 <th>user ID</th>
42                 <th>User Name</th>
43                 <th>User Age</th>
44                 <th>operation</th>
45             </tr>
46             <tr th:each="user : ${list}">
47                 <td th:text="${user.id}"></td>
48                 <td th:text="${user.name}"></td>
49                 <td th:text="${user.age}"></td>
50                 <td>
51                     <a th:href="@{/users/findUserById(id=${user.id})}" class="btn btn-warning">Update User</a>
52                     <a th:href="@{/users/delUser(id=${user.id})}" class="btn btn-danger">delete user</a>
53                 </td>
54             </tr>
55         </table>
56     </div>
57     <div class="col-md-2"></div>
58 </div>
59 </body>
60 </html>
 1 <!DOCTYPE html>
 2 <html xmlns:th="http://www.w3.org/1999/xhtml">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>Add User</title>
 6 </head>
 7 <body>
 8 <h1 style="text-align: center">user management~New Users</h1>
 9 <hr/>
10 
11 <div style="text-align: center">
12     <form th:action="@{/users/addUser}" method="post">
13         User name:<input type="text" name="name"/><br/>
14         User age:<input type="text" name="age"/><br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
15         <input type="submit" value="Determine"/> &nbsp;&nbsp;&nbsp;
16         <input type="reset" value="Reset"/><br/>
17     </form>
18 </div>
19 
20 </body>
21 </html>
 1 <!DOCTYPE html>
 2 <html xmlns:th="http://www.w3.org/1999/xhtml">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>Insert title here</title>
 6 </head>
 7 <body>
 8 
 9 <h1 style="text-align: center">user management~Modify User</h1>
10 <hr/>
11 
12 <div style="text-align: center">
13     <form th:action="@{/users/editUser}" method="post">
14         <input type="hidden" name="id" th:field="${user.id}"/>
15         User name:<input type="text" name="name" th:field="${user.name}"/><br/>
16         User age:<input type="text" name="age" th:field="${user.age}"/><br/>
17         <input type="submit" value="Determine"/><br/>
18     </form>
19 </div>
20 </body>
21 </html>

Create a startup class as follows:

 1 package com.bie.springboothello;
 2 
 3 import org.mybatis.spring.annotation.MapperScan;
 4 import org.springframework.boot.SpringApplication;
 5 import org.springframework.boot.autoconfigure.SpringBootApplication;
 6 
 7 @SpringBootApplication
 8 // @MapperScan Notes, User Scan MyBatis Of Mapper Interface to generate proxy objects from scanned interfaces
 9 @MapperScan(value = "com.bie.springboothello.mapper")
10 public class SpringbootHelloApplication {
11 
12     public static void main(String[] args) {
13         SpringApplication.run(SpringbootHelloApplication.class, args);
14     }
15 
16 
17 }

Run as follows:

Add user interface.

Modify the user's interface.

 

 

Error Description 1, this problem is due to the server Timezone problem, configure it after application.properties.As follows:

1 spring.datasource.url=jdbc:mysql://localhost:3306/biehl?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC

An error occurred as follows:

 1 java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the 'serverTimezone' configuration property) to use a more specifc time zone value if you want to utilize time zone support.
 2     at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129) ~[mysql-connector-java-8.0.19.jar:8.0.19]
 3     at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-java-8.0.19.jar:8.0.19]
 4     at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89) ~[mysql-connector-java-8.0.19.jar:8.0.19]
 5     at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63) ~[mysql-connector-java-8.0.19.jar:8.0.19]
 6     at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73) ~[mysql-connector-java-8.0.19.jar:8.0.19]
 7     at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:76) ~[mysql-connector-java-8.0.19.jar:8.0.19]
 8     at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836) ~[mysql-connector-java-8.0.19.jar:8.0.19]
 9     at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456) ~[mysql-connector-java-8.0.19.jar:8.0.19]
10     at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246) ~[mysql-connector-java-8.0.19.jar:8.0.19]
11     at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:197) ~[mysql-connector-java-8.0.19.jar:8.0.19]
12     at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1558) ~[druid-1.1.10.jar:1.1.10]
13     at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1623) ~[druid-1.1.10.jar:1.1.10]
14     at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2468) ~[druid-1.1.10.jar:1.1.10]
15 Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the 'serverTimezone' configuration property) to use a more specifc time zone value if you want to utilize time zone support.
16     at sun.reflect.GeneratedConstructorAccessor30.newInstance(Unknown Source) ~[na:na]
17     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_191]
18     at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_191]
19     at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61) ~[mysql-connector-java-8.0.19.jar:8.0.19]
20     at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:85) ~[mysql-connector-java-8.0.19.jar:8.0.19]
21     at com.mysql.cj.util.TimeUtil.getCanonicalTimezone(TimeUtil.java:132) ~[mysql-connector-java-8.0.19.jar:8.0.19]
22     at com.mysql.cj.protocol.a.NativeProtocol.configureTimezone(NativeProtocol.java:2118) ~[mysql-connector-java-8.0.19.jar:8.0.19]
23     at com.mysql.cj.protocol.a.NativeProtocol.initServerSession(NativeProtocol.java:2142) ~[mysql-connector-java-8.0.19.jar:8.0.19]
24     at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1310) ~[mysql-connector-java-8.0.19.jar:8.0.19]
25     at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:967) ~[mysql-connector-java-8.0.19.jar:8.0.19]
26     at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:826) ~[mysql-connector-java-8.0.19.jar:8.0.19]
27     ... 6 common frames omitted

Error Description 2, there are many problems, Baidu also has a lot of explanations, you can also record it.Because of the idea tool used, springboot was developed, and because UsersMapper.xml is in a different location, my map file is in a different location, and the project structure is shown below.

In mybatis, there is a problem with the dao interface and mapper configuration file in mapping bindings. In short, the interface and xml are either missing or found but not matched.The error is as follows:

 1 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.bie.springboothello.mapper.UsersMapper.insertUser
 2     at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:235) ~[mybatis-3.5.3.jar:3.5.3]
 3     at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:53) ~[mybatis-3.5.3.jar:3.5.3]
 4     at org.apache.ibatis.binding.MapperProxy.lambda$cachedMapperMethod$0(MapperProxy.java:98) ~[mybatis-3.5.3.jar:3.5.3]
 5     at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660) ~[na:1.8.0_191]
 6     at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:97) ~[mybatis-3.5.3.jar:3.5.3]
 7     at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:92) ~[mybatis-3.5.3.jar:3.5.3]
 8     at com.sun.proxy.$Proxy63.insertUser(Unknown Source) ~[na:na]
 9     at com.bie.springboothello.service.impl.UsersServiceImpl.addUser(UsersServiceImpl.java:21) ~[classes/:na]
10     at com.bie.springboothello.service.impl.UsersServiceImpl$$FastClassBySpringCGLIB$$6c792bea.invoke(<generated>) ~[classes/:na]
11     at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.2.5.RELEASE.jar:5.2.5.RELEASE]
12     at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:771) ~[spring-aop-5.2.5.RELEASE.jar:5.2.5.RELEASE]
13     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.2.5.RELEASE.jar:5.2.5.RELEASE]
14     at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749) ~[spring-aop-5.2.5.RELEASE.jar:5.2.5.RELEASE]
15     at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:366) ~[spring-tx-5.2.5.RELEASE.jar:5.2.5.RELEASE]
16     at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118) ~[spring-tx-5.2.5.RELEASE.jar:5.2.5.RELEASE]
17     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.5.RELEASE.jar:5.2.5.RELEASE]
18     at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749) ~[spring-aop-5.2.5.RELEASE.jar:5.2.5.RELEASE]
19     at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:691) ~[spring-aop-5.2.5.RELEASE.jar:5.2.5.RELEASE]
20     at com.bie.springboothello.service.impl.UsersServiceImpl$$EnhancerBySpringCGLIB$$9682ec5a.addUser(<generated>) ~[classes/:na]
21     at com.bie.springboothello.controller.UsersController.addUser(UsersController.java:55) ~[classes/:na]
22     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_191]
23     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_191]
24     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_191]
25     at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_191]
26     at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190) ~[spring-web-5.2.5.RELEASE.jar:5.2.5.RELEASE]
27     at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) ~[spring-web-5.2.5.RELEASE.jar:5.2.5.RELEASE]
28     at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105) ~[spring-webmvc-5.2.5.RELEASE.jar:5.2.5.RELEASE]
29     at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:879) ~[spring-webmvc-5.2.5.RELEASE.jar:5.2.5.RELEASE]
30     at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793) ~[spring-webmvc-5.2.5.RELEASE.jar:5.2.5.RELEASE]
31     at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.2.5.RELEASE.jar:5.2.5.RELEASE]
32     at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040) ~[spring-webmvc-5.2.5.RELEASE.jar:5.2.5.RELEASE]
33     at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) ~[spring-webmvc-5.2.5.RELEASE.jar:5.2.5.RELEASE]
34     at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.2.5.RELEASE.jar:5.2.5.RELEASE]
35     at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) ~[spring-webmvc-5.2.5.RELEASE.jar:5.2.5.RELEASE]
36     at javax.servlet.http.HttpServlet.service(HttpServlet.java:660) ~[tomcat-embed-core-9.0.33.jar:9.0.33]
37     at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.2.5.RELEASE.jar:5.2.5.RELEASE]
38     at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) ~[tomcat-embed-core-9.0.33.jar:9.0.33]
39     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-9.0.33.jar:9.0.33]
40     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.33.jar:9.0.33]
41     at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.33.jar:9.0.33]
42     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.33.jar:9.0.33]
43     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.33.jar:9.0.33]
44     at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-5.2.5.RELEASE.jar:5.2.5.RELEASE]
45     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.5.RELEASE.jar:5.2.5.RELEASE]
46     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.33.jar:9.0.33]
47     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.33.jar:9.0.33]
48     at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-5.2.5.RELEASE.jar:5.2.5.RELEASE]
49     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.5.RELEASE.jar:5.2.5.RELEASE]
50     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.33.jar:9.0.33]
51     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.33.jar:9.0.33]
52     at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-5.2.5.RELEASE.jar:5.2.5.RELEASE]
53     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.5.RELEASE.jar:5.2.5.RELEASE]
54     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.33.jar:9.0.33]
55     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.33.jar:9.0.33]
56     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) ~[tomcat-embed-core-9.0.33.jar:9.0.33]
57     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-9.0.33.jar:9.0.33]
58     at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) [tomcat-embed-core-9.0.33.jar:9.0.33]
59     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) [tomcat-embed-core-9.0.33.jar:9.0.33]
60     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.33.jar:9.0.33]
61     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) [tomcat-embed-core-9.0.33.jar:9.0.33]
62     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) [tomcat-embed-core-9.0.33.jar:9.0.33]
63     at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:373) [tomcat-embed-core-9.0.33.jar:9.0.33]
64     at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-embed-core-9.0.33.jar:9.0.33]
65     at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) [tomcat-embed-core-9.0.33.jar:9.0.33]
66     at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1594) [tomcat-embed-core-9.0.33.jar:9.0.33]
67     at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.33.jar:9.0.33]
68     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_191]
69     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_191]
70     at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.33.jar:9.0.33]
71     at java.lang.Thread.run(Thread.java:748) [na:1.8.0_191]

Note: Mapper interface development follows the following specifications:

1) The namespace in the Mapper.xml file has the same class path as the mapper interface.
2), the Mapper interface method name, and the id of each state defined in Mapper.xml are the same.
3) The input parameter type of the Mapper interface method is the same as the type of parameterType of each sql defined in mapper.xml.
4) The output parameter type of the Mapper interface method is the same as the resultType of each sql defined in mapper.xml.


In addition to configuring the resource in pom.xml and managing the *Mapper.xml file in the resource folder, you can also solve this problem.

Need to add, configure below.

1 # Print sql statements in the background
2 mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
3 
4 # Specify sql mapping file location, all.xml files under mapper are mapping files
5 mybatis.mapper-locations=classpath:mapper/*Mapper.xml

The project structure is as follows:

Tags: Java MySQL Spring Apache

Posted on Mon, 11 May 2020 18:54:35 -0700 by spyke01