导入依赖
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.2</version>
</dependency>
在yml文件中配置
mybatis:
mapper-locations: classpath:mapping/*.xml
config-location: classpath:mybatis-config.xml
type-aliases-package: com.pzh.domain
在resources资源文件下创建mapping文件夹
然后创建UserMapper.xml配置文件
<?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.pzh.myproject.mapper.UserMapper">
<select id="findAllUser" resultType="User">
select * from user
</select>
</mapper>
然后在resources资源文件下创建mybatis-config.xml
<?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>
</configuration>
加入mapperScan注解
@MapperScan("com.pzh.myproject.mapper")
public class MyProjectApplication {
public static void main(String[] args) {
SpringApplication.run(MyProjectApplication.class, args);
}
}