The second step is to add maven's mybatis coordinates, mysql-driven coordinates (that is, import mybatis and mysql connector dependencies)
3. Create an entity class
4. Create dao interface
Then define the database operation method
The specific code is pasted on mybatis
5. Create the mapping file of the configuration file sql used by mybatis. This file is an xml file.
6. Create a configuration file used by mybatis
Create a new mybatis.xml file under the resource folder of main and paste the content of the xml file found by mybatis into idea.
This file also needs to be found online and then pasted into the file to complete
https://mybatis.org/mybatis-3/zh/getting-started.html
<?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">
<configuration>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="${driver}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="org/mybatis/example/BlogMapper.xml"/>
</mappers>
</configuration>
Create the mybatis class and access the database through mybatis