1. Set up the environment
1. Connect to the MySql database and execute the following SQL statements:
2. Create a new ordinary Maven project and
delete the src directory to make this project called the parent project.
Import dependencies.
2. Create a module
. Create an ordinary Maven module under the parent project.
Write the
content of the mybatis core configuration file :
create a tool class
to create a package in the java directory, and the tool class
code is as follows:
three, write code
1, write entity class
2, write interface class
Create a UserMapper.xml
4.
If the test appears: org.apache.ibatis.binding.BindingException: Type interface com.kuang.dao.UserDao is not known to the MapperRegistry. Error, we need to configure the core configuration file mybatis-config.xml After registering each Mapper.xml in
this modification, a Caused by: java.io.IOException: Could not find resource com/kuang/dao/UserMapper.xml error will appear. This is the problem that the resource file cannot be exported in the maven project. The following code is added to the pom.xml of the parent project and module