Tag Archives: mybatis

Mybatis sets the primary key Auto-Increment error: No setter found for the keyProperty

Mybatis sets the auto increment of the primary key, and an error is reported: no setter found for the keyproperty

SQL statement in XML:

<insert id="registerReader" parameterType="com.by.tsgl.bean.Reader" useGeneratedKeys="true" keyProperty="reader_id">
    insert into reader(deposit_num,borrowing_num,reader_state,grade_id,user_id)
    values(0,0,"normal",1,#{user_id});
</insert>

Test Times Error
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.ExecutorException: Error getting generated key or setting result to parameter object. Cause: org.apache.ibatis.executor.ExecutorException: No setter found for the keyProperty 'reader_id' in 'java.lang.String'.
Solution:
Remove the keyProperty property from the insert tag
Change it to.

<insert id="registerReader" parameterType="com.by.tsgl.bean.Reader" useGeneratedKeys="true">

Cause analysis

The corresponding value in keyProperty is a property of the entity class, not a database field.

The fields that have been set up for primary key auto-increment in the database only need to configure the useGeneratedKeys attribute.

useGeneratedKeys=“true” keyProperty=“id”
When useGeneratedKeys is set to true, it means that if the inserted table id has an auto-incrementing column as the primary key, JDBC is allowed to support automatic primary key generation.

keyProperty=“id” The automatically generated primary key id can be returned to the id of the passed in object . Since the object we passed in does not have the id field, it naturally does not have its set method, so an error will be reported.

What if there is no primary key in the inserted table?

Can use attributeskeyColumn

<insert id="registerReader" parameterType="com.by.tsgl.bean.Reader" useGeneratedKeys=true keyProperty="userId" keyColumn="user_id">
    

This annotation means to use the primary key automatically increased by the database and user from the table_ In the ID field, put the data into the member variable userid of the incoming object. If we have specified the primary key in the database table, the keycolumn attribute can be defaulted</ ol>

The following is from the mybatis document

usegeneratedkeys (only applicable to insert and update) this will make mybatis use JDBC’s getgeneratedkeys method to retrieve the primary key generated internally by the database (such as the auto increment field of relational database management systems such as MySQL and SQL Server). The default value is false
keyproperty (only applicable to insert and update) specifies the property that can uniquely identify the object. Mybatis will use the return value of getgeneratedkeys or the selectkey sub element of the insert statement to set its value. The default value is unset. If more than one column is generated, multiple attribute names can be separated by commas.

[Solved] thymeleaf.TemplateEngineException processing template “main“: An error happened during template pars

preface

This project uses the thymeleaf template in the springboot project. The main error is that the front-end HTML page uses thymeleaf to obtain the value passed from the background. There is a problem (the value cannot be obtained, or it is empty and null)

Error message

1. error 1: the forwarded is used as redirect:/main

2021-11-18 21:02:01.321 ERROR 9272 — [nio-8082-exec-4] org.thymeleaf.TemplateEngine : [THYMELEAF][http-nio-8082-exec-4] Exception processing template “main”: An error happened during template parsing (template: “class path resource [templates/main.html]”)
*
* org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: “class path resource [templates/main.html]”)
* at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:241) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE]
* caused by: org.thymeleaf.exceptions.templateprocessingexception: exception evaluating springel expression: "page. Getcurrent()" (template: "main" - line 86, col 17)
* redirection cannot be used here: otherwise, the front-end data cannot be obtained through thymeleaf

2. error 2: null value error

 org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field ‘records’ cannot be found on null

Solution:

1. The first error is that when the data queried in the background is sent to the front-end HTML page, there is no corresponding value, and redirection cannot be used, otherwise the front-end data cannot be obtained through thymeleaf. Remove redirect directly and return “main” directly “;
2. The second error is somewhat similar to the first one. This error can find the corresponding data in the background on the page, but the paging data cannot be obtained without corresponding request. If you enter this page directly from the login interface, it is an error because the data of another requested page paging query is used, and there is no query directly The paging data is null. Therefore, you can only send a request to query the page paging data before it can successfully reach the main page.

Corresponding part code

1. Front end code main.html

<!--Employee data table display-->
<div class="container table-responsive" style="margin-top: 50px">
    <table class="table table-bordered">
        <caption class="caption"><a th:href="@{/showemp}">Display employee information</a> </caption>
        <thead>
            <tr>
                <th>ID</th>
                <th>ID</th>
                <th>Name</th>
                <th>Password</th>
                <th>operate</th>
            </tr>
        </thead>
        <tbody>
            <tr th:each="book,statu:${page.records}">
                <th>[[${statu.count}]]</th>
                <td th:text="${book.id}"></td>
                <td>[[${book.name}]]</td>
                <td>[[${book.password}]]</td>
                <td>
                    <a th:href="@{/delete}" type="button" class="btn btn-danger btn-sm">delete</a>
                    <a th:href="@{/update}" type="button" class="btn btn-info btn-sm">update</a></td>
            </tr>
        </tbody>
    </table>
</div>

2.CrudController.java

@Controller
public class CrudController {
   @Autowired
   BookServiceImpl bookService;

   @GetMapping("/showemp")
   public String selectAll(@RequestParam(value = "pn",defaultValue = "1")Integer pn,
                           Model model){
       Page<Book> page = new Page<>(pn,2);
       Page<Book> bookPage = bookService.page(page, null);
       model.addAttribute("page",bookPage);
       System.out.println(bookPage.getCurrent());
       System.out.println(bookPage.getRecords().size());
       /**
        * 2021-11-18 21:02:01.321 ERROR 9272 --- [nio-8082-exec-4] org.thymeleaf.TemplateEngine             : [THYMELEAF][http-nio-8082-exec-4] Exception processing template "main": An error happened during template parsing (template: "class path resource [templates/main.html]")
        *
        * org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/main.html]")
        * 	at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:241) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE]
        * Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "page.getCurrent()" (template: "main" - line 86, col 17)
        * Redirection cannot be used here: otherwise the front-end data cannot be obtained through thymeleaf
        */
//        return "redirect:/main";
       return "main";
   }
}

3.LoginController.java

@PostMapping("/login")
    public String LoginValidation(Book book,
                                  RedirectAttributes redirectAttributes){
        String name = book.getName();
        String password = book.getPassword();
        Map<String,Object> map = new HashMap<>();
        map.put("name",name);
        map.put("password",password);
        QueryWrapper<Book> queryWrapper = new QueryWrapper<>();
        queryWrapper.ge("name",name );
        queryWrapper.ge("password",password);
        Book one = bookService.getOne(queryWrapper);
        if (one.toString()!=null){
            /**
             * org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'records' cannot be found on null
             * It is wrong to enter this page directly from the login interface, because the page paging query data requested by showemp is used here, and there is no query when entering directly, and the page paging data is null.
              * So you can only successfully reach the main page by sending a showemp request to query the page paging data.
             */
//            return "redirect:/main";
            return "redirect:/showemp";
        }
        return "login";
    }

[Solved] java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corres

0. Foreword: this error is an error reported by using mybatis in the spring boot project to query a piece of data in the database according to the ID value

1. Error message

2021-11-14 15:37:38.168 ERROR 9936 --- [nio-8086-exec-7] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: 
### Error querying database.  Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
### The error may exist in file [E:\smallTools\idea\code\spring\springboot-new-2021_11_09\springboot-new-mybatis\target\classes\mybatis\mapper\BookMapper.xml]
### The error may involve com.feng.mybatis.mapper.BookMapper.getBookById-Inline
### The error occurred while setting parameters
### SQL: select * from book where id={#id}
### Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1] with root cause

java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) ~[mysql-connector-java-8.0.27.jar:8.0.27]

2. Mapper.xml file content

<select id="getBookById" parameterType="com.feng.mybatis.bean.Book">
        select * from book where id={#id}
</select>

3. Error reason: the SQL statement is written incorrectly. It should be where id = #{id}

<select id="getBookById" parameterType="com.feng.mybatis.bean.Book">
        select * from book where id=#{id}
</select>

[Solved] Mybatis integrates PageHelper and uses sqlserver paging error

The environment uses mybatis plus, the paging plug-in: PageHelper 5.2.0, and the database uses sqlserver2012 or above

In fact, the paging plug-in is ultimately handled by the mybatis interceptor, so it is equivalent to the mybatis environment.

Using paging

 PageHelper.startPage(1,10); // Pagination
  orderMapper.list(); // Follow the execution

Then an error will be reported

SQL: SELECT  id,product_name,xxxx,xxxxx  FROM product_xxxx  OFFSET ?ROWS FETCH NEXT ?ROWS ONLY
### Cause: com.microsoft.sqlserver.jdbc.SQLServerException: “@P0”There is a grammatical error nearby.
; uncategorized SQLException; SQL state [S0001]; error code [102]; There is a syntax error near "@P0". ; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: There is a syntax error near "@P0".

Finally, after checking, it is found that the paging syntax offset and fetch used by PageHelper are sqlserver’s support for sorting.

Therefore, if you want to use this plug-in to page, you need to add sorting.

PageHelper.startPage(1,10,"xxxx sorted table field name, not attribute name");
orderMapper.list(); // Follow the execution

Or use the default sort field

PageHelper.startPage(1,10,"CURRENT_TIMESTAMP");
orderMapper.list(); //Follow up

How to Solve idea com.baomidou Error

Completely solve the error reported by com.baomidou in idea

Add in pom.xml:

		<dependency>
			<groupId>com.baomidou</groupId>
			<artifactId>mybatis-plus-boot-starter</artifactId>
			<version>3.4.2<ersion>
		</dependency>

Clear all mybatis and mybatis plus related configurations in the YML file and add:

mybatis-plus:
  type-aliases-package: com.peanut.entity
  mapper-locations: classpath:mappers

Select the item and right-click Maven -> Reload project
as shown in the figure, com.baidu no longer turns red:

[Solved] SQL Error: Method queryTotal execution error of sql

In a connection query, there is no problem with the query in the MySQL query tool. It is pasted into the mapper.xml file in the project, but the runtime reports mybatisplusexception: error: method querytotal execution error of SQL:

 SELECT
        ANY_VALUE(e.id)  AS "id",
        ANY_VALUE(e.project_no) AS "projectNo",
        ANY_VALUE(sampleIn.sample_id)  AS "fieldNumber",
        ANY_VALUE(e.subject_no) AS "laboratoryNumber",
        ANY_VALUE(e.type) AS "type",
        ANY_VALUE(d.sampling_location) AS "location",
        ANY_VALUE(sampleIn.in_quantity)   AS "inquatity",
        ANY_VALUE(sampleIn.create_date)  AS "createDate",
        ANY_VALUE(sys_user.name)  AS "createUser",          
        ANY_VALUE(s. project_no)  AS "projectNoName",
        ANY_VALUE(s.subject_name)   AS "subjectName",
        ANY_VALUE(sd.name) AS "saveCondition",
        ANY_VALUE(sa.location) AS "location",
        ANY_VALUE(DATE_FORMAT(sa.shelf_life,'%Y-%m-%d'))AS"shelfLife"
        FROM labcode e
        LEFT JOIN labprojects s ON e.project_no = s.id
        LEFT JOIN labprojectplan n ON s.id = n.project_no        
        LEFT JOIN labprojectplan_field d ON n.id = d. lab_project_plan_id  AND e.serial_number = d.serial_number AND e.letter_code =d.letter_code    
        LEFT JOIN labsubjectsample sa ON e.id =sa.laboratory_number
        LEFT JOIN laboratorysamplein sampleIn ON sampleIn.code_id = e.id
        LEFT JOIN sys_user ON sampleIn.create_user=sys_user.user_id
        LEFT JOIN sys_dict sd ON sd.code = sa.save_condition
        WHERE 1 = 1
        AND s.is_delete = 0
        AND e.is_delete=0
        AND e.subject_no LIKE '%B'
        AND e.type=3
       
        GROUP BY e.id     
        ORDER BY ANY_VALUE(sampleIn.create_date) DESC

After going online to search, it was confirmed that it was the problem of where conditions, so they were eliminated one by one, and finally locked on several is_delete fields, which are of char type in the database. The database query tool supports direct use of 0 and 1 to query, and MyBatis needs to contact the database Keep consistent in the middle, and finally, change the where part to

WHERE 1 = 1
        AND s.is_delete = '0'
        AND e.is_delete='0'
        AND e.subject_no LIKE '%B'
        AND e.type='3'

Problem-solving

This exception is basically the problem of where conditions, and type mismatch is only one of them. Other problems include condition null value, keyword conflict with framework and so on. As long as you are careful when writing code, think more about avoiding exceptions, be patient when problems occur, check them one by one, and be good at summarizing after problems are solved, you can accumulate experience and grow gradually on the way of writing code.

Error attempting to get column ‘xxxxx’ from result set — after Lombok is annotated with builder, mybatis cannot recognize the correct type of field

Pit stepping record – after Lombok is annotated with builder, mybatis cannot recognize the correct type of field

After adding Lombok to the entity class, sometimes we will use @ builder annotation, so we don’t need to write too many set methods to define the attribute content, which makes our code more elegant. Once the @ builder annotation is added to the entity class, it will cause problems in our mybatis mapping database fields

The questions are as follows

org.springframework.dao.DataIntegrityViolationException: Error attempting to get column 'username' from result set.  Cause: java.sql.SQLDataException: Cannot determine value type from string 'zhangsa'
; Cannot determine value type from string 'zhangsa'; nested exception is java.sql.SQLDataException: Cannot determine value type from string 'zhangsa'

note: when using @ builder annotation, a full parameter structure will be generated, resulting in the disappearance of no parameter structure

terms of settlement

    we can directly remove @ builder annotation, and there will be no problem for mybatis to query the database. We can generate parametric and nonparametric constructs in entity classes (you can add them manually or add annotations @ allargsconstructor , @ noargsconstructor )

    if it is still abnormal, you should check whether your entity class and database type mapping do not correspond

    Hold fireworks to seek life, poetic to seek love

[Solved] Mybatis-Plus Error: Invalid bound statement (not found)

Mybatis plus reports an error: invalid bound statement (not found)

After integrating mybatis plus in the spring boot project, it is found that the user-defined query method will report an error: “invalid bound statement (not found): * * *.” your method “, which means that your user-defined method cannot be found in the XML file. Various methods are tried and the problem is finally solved. This problem exists in the following situations:

1. Mapper file and XML file cannot correspond

1. Check whether mapper file and XML file names are consistent

UserMapper and UserMapper.xml

2. Check whether the attribute configuration of namespace in the XML file corresponds to the corresponding mapper file

<mapper namespace="com.*.*.mapper.UserMapper">

3. Check whether the method binding ID in the XML file is consistent

Mapper:
    List<User> getUserList();
xml:
    <select id="getUserList" resultType="com.*.*.entity.User">
        SELECT * FROM user
    </select>

2. The XML file is placed in the resources directory at different levels and is not packaged into the target

By default, all will be packaged. Check whether the property of not packaging is configured in the POM file, and modify it

Note: this configuration is to package the resources directory and check the differences

	<build>
        <!-- Pack the files in the resources directory -->
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.*</include>
                </includes>
            </resource>
        </resources>
     </build>

(focus on configuration, which is also my problem) third, the XML file is placed in the resources directory at different levels and has been packaged into the target, but the corresponding method cannot be found

It is thought that after packaging, you can match according to the name. Finally, it is found that even if the XML file is packaged, it still belongs to a different level from mapper, so check whether the mybatis plus configuration matching the location of the XML file is missing

mybatis-plus.mapper-locations = classpath:mapping/*.xml
# The "mapping" in this configuration corresponds to the name of the directory where your xml is located

Mybatis query error: Exception in thread “main” org.apache.ibatis.exceptions.PersistenceException…

1. Error Messages:
Mapped Statements collection does not contain value for com.lsy.mapper.UsersMapper.selectUsersAll

Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.lsy.mapper.UsersMapper.selectUsersAll
### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.lsy.mapper.UsersMapper.selectUsersAll

One of the reasons:
mapper namespace writes the wrong file name:

usersmapper in mapper.xml file is written as usermapper

The correct wording is as follows:

<?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.lsy.mapper.UsersMapper">
    <select id="selectUsersAll" resultType="com.lsy.pojo.Users">
        select * from users
    </select>
</mapper>

Mybatis reports an error (error building sqlsession.) when using annotations without deleting redundant files

First, the SQL statement is read by using the mapping configuration file
the file is iuserdao.xml, as follows:

package com.wwh.dao;

import com.wwh.domain.User;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * Created By DELL on 2021/10/21-17:41
 * Persistence layer interface for users
 */
public interface IUserDao {
    /**
     * Query all operations
     * @return
     */
    @Select("select * from user")
    List<User> findAll();
}

The main profile is:


```css
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<!--The main configuration file for mybatis - >
<configuration>
    <! --configuration-environments-->
    <environments default="mysql">
        <! --configure the type of mysql -->
        <environment id="mysql">
            <! --configure the type of transaction -->
            <transactionManager type="JDBC"></transactionManager>
            <! -- Configure data source (connection pool) -->
            <dataSource type="POOLED">
                <! -- Configure the four basic information for connecting to the database -- >
                <property name="driver" value="com.mysql.jdbc.Driver"/>
                <property name="url" value="jdbc:mysql://localhost:3306/eesy"/>
                <property name="username" value="root"/>
                <property name="password" value="123456"/>
            </dataSource>

        </environment>
    </environments>

    <! -- Specify the location of the mapping profile, the mapping profile refers to a separate profile for each dao
        If the configuration is done with annotations, the class attribute should be used here to specify the fully qualified class name of the annotated dao
    -->
    <mappers>
        <mapper resource="com/wwh/dao/IUserDao.xml"/>
    </mappers>
</configuration>

Then, the SQL is read by annotation, and the main configuration file is changed to:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<!--The main configuration file for mybatis - >
<configuration>
    <! --configuration-environments-->
    <environments default="mysql">
        <! --configure the type of mysql -->
        <environment id="mysql">
            <! --configure the type of transaction -->
            <transactionManager type="JDBC"></transactionManager>
            <! -- Configure data source (connection pool) -->
            <dataSource type="POOLED">
                <! -- Configure the four basic information for connecting to the database -- >
                <property name="driver" value="com.mysql.jdbc.Driver"/>
                <property name="url" value="jdbc:mysql://localhost:3306/eesy"/>
                <property name="username" value="root"/>
                <property name="password" value="123456"/>
            </dataSource>

        </environment>
    </environments>

    <! -- Specify the location of the mapping profile, the mapping profile refers to a separate profile for each dao
        If the configuration is done with annotations, the class attribute should be used here to specify the fully qualified class name of the annotated dao
    -->
    <mappers>
        <mapper class="com.wwh.dao.IUserDao"/>
    </mappers>
</configuration>

The notes are:

package com.wwh.dao;

import com.wwh.domain.User;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * Created By DELL on 2021/10/21-17:41
 * Persistence layer interface for users
 */
public interface IUserDao {
    /**
     * Query all operations
     * @return
     */
    @Select("select * from user")
    List<User> findAll();
}

When running the mapping configuration file discovery program, it can run through, but when running the annotation program, it is found that an error is reported:

### Error building SqlSession.
### The error may exist in com/wwh/dao/IUserDao.xml
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.wwh.dao.IUserDao.findAll
	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
	at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:80)
	at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:64)
	at com.wwh.test.MybatisTest.main(MybatisTest.java:27)
Caused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.wwh.dao.IUserDao.findAll
	at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:121)
	at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:99)
	at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:78)
	... 2 more
Caused by: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.wwh.dao.IUserDao.findAll
	at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java:872)
	at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java:844)
	at org.apache.ibatis.session.Configuration.addMappedStatement(Configuration.java:668)
	at org.apache.ibatis.builder.MapperBuilderAssistant.addMappedStatement(MapperBuilderAssistant.java:302)
	at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.parseStatement(MapperAnnotationBuilder.java:351)
	at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.parse(MapperAnnotationBuilder.java:134)
	at org.apache.ibatis.binding.MapperRegistry.addMapper(MapperRegistry.java:72)
	at org.apache.ibatis.session.Configuration.addMapper(Configuration.java:741)
	at org.apache.ibatis.builder.xml.XMLConfigBuilder.mapperElement(XMLConfigBuilder.java:381)
	at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:119)
	... 4 more

Process finished with exit code 1

Viewing the error information, we can see that the reason is that your iuserdao.xml has not been deleted. After the annotation method is adopted, the relevant mapping configuration file has no effect. If it is not deleted, an error will be reported (even if it is marked as excluded)
after deletion, you can run through:

The springboot integration mybatis reported an error. The parameter cannot be found

Today, I stepped on a pit when I implemented a login page in springboot and mybatis

It always shows that the parameter cannot be found, and many blogs on the Internet have not found the reason

  Finally, it was pointed out by the leaders in the group that the @ param annotation was missing in the usermapper parameter

 

This SQL statement is used in usermapper, resulting in an error

 

  So I sorted out the usage of a wave of @ param annotations from the Internet

1. Use @ param annotation

When writing SQL statements in the following way:

    @ Select(“select column from table where userid = #{userid} “)
    public int selectColumn(int userid);

When you use the @ param annotation to declare parameters, you can use either #{} or ${}.

    @ Select(“select column from table where userid = ${userid} “)
    public int selectColumn(@Param(“userid”) int userid);

When you do not use the @ param annotation to declare parameters, you must use the use #{} method. If you use ${}, an error will be reported.

    @ Select(“select column from table where userid = ${userid} “)
    public int selectColumn(@Param(“userid”) int userid);

2. Do not use @ param annotation

··When the @ param annotation is not used, there can only be one parameter and it is a java bean. JavaBean properties can be referenced in SQL statements, and only JavaBean properties can be referenced.

    // Here ID is the attribute of user

    @ Select(“SELECT * from Table where id = ${id}”)
    Enchashment selectUserById(User user);
1