first step:
<-! Mybatis automatic starter comprises introducing jdbc jdbc so no reliance again -> <dependency> <the groupId> org.mybatis.spring.boot </ the groupId> <the artifactId> MyBatis-Spring-Boot-Starter </ the artifactId > <Version> 1.3 . 2 </ Version> </ dependency>
Step 2: Perform configuration file in yml
# Configure mybatis relevant path created in the resources folder mybatis folders and
mybatis:
## # mapping configuration file path Mapper -locations: the CLASSPATH: mybatis / Mapper / * .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.tiangong.spring_boot_test.mapper.UserMapper">
<select id="getUserByUsername" resultType="com.tiangong.spring_boot_10_bill.entities.User">
<!--upper:将英文转化为大写进行校验-->
select * from `user` where upper(username)= upper (#{username})
</select>
<select id="getUsers" resultType="com.tiangong.spring_boot_10_bill.entities.User">
select * from `user` where 1=1
<if test="username != null and username != ''">
and username like '%${username}%'
</if>
</select>
</mapper>
# ## core configuration file path
config-location: classpath: mybatis / mybatis-config.xml
mybatis-config.xml file to see what content
<?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>
<!-- 核心配置文件-->
<settings>
<!--开启驼峰命名规则-->
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings>
</configuration>
third step:
Was added in the main scanning method mapper
import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @MapperScan("com.tiangong.spring_boot_test.mapper") @SpringBootApplication public class SpringBoot10BillApplication { public static void main(String[] args) { SpringApplication.run(SpringBoot10BillApplication.class, args); } }
Or use with @Mapper @MapperScan ( "com.tiangong.spring_boot_test.mapper ")
If the latter do not always use the annotated mapper mapper to create the position shown below