Home > Java > javaTutorial > Solution to error message when configuring MyBatis

Solution to error message when configuring MyBatis

怪我咯
Release: 2017-06-25 10:24:04
Original
2453 people have browsed it

The error message when configuring MyBatis is as follows:

Invalid bound statement (not found): com.shizongger.chapter2.mapper.UserMapper.insertUser

Simple Understanding means not being able to find the correct sentences. It is usually caused by the file mismatch between mapper.xml and mapper.java. There are roughly four ways to introduce a mapper:
1. Use the file path to introduce the mapper

        <mapper></mapper>
        <mapper></mapper>
Copy after login
Copy after login
Copy after login

2. Use the package name to introduce the mapper

<package></package>
Copy after login

3. Use class registration to introduce the mapper

        <mapper></mapper>
        <mapper></mapper>
Copy after login
Copy after login
Copy after login

4.xxxMapper.xml introduces mapper

        <mapper></mapper>
        <mapper></mapper>
Copy after login
Copy after login
Copy after login

These four methods of introducing mapper have their own characteristics. I recommend using the first or second method of using scanned packages. But when using the second one, be careful: the names of xxxMapper.java and xxxMapper.xml must be exactly the same!
The reason for this error is that I mistakenly wrote UserMapper.xml as userMapper.xml and used lowercase letters at the beginning, which caused the program to fail to scan the mapper when scanning the package and cause an error.
Solution to error message when configuring MyBatis

Why did I make this mistake? Because when I was referring to Chapter 3, page 57 of "MyBatis Technical Principles and Practices in a Simple Language" (Electronic Industry Press-Yang Kaizhen), the author gave a code example of userMapper.xml and started the userMapper.xml file with lowercase letters. . And where mapper.xml is used on page 72, the author has the habit of starting with mapper.xml with a lowercase letter. I mistakenly thought it was caused by the default requirement of MyBatis to comply with camel case naming and the first letter must be lowercase.
So, I would like to advise authors who write technical books not to be impetuous, but to be worthy of the readers!

The above is the detailed content of Solution to error message when configuring MyBatis. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template