官网
MyBatis中文网
SpringBoot依赖
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.1</version>
</dependency>
配置
mybatis:
mapper-locations: classpath:resources.mapper
configuration:
map-underscore-to-camel-case: true
type-aliases-package: com.aa.dsf
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.###.###.###.class" resultType="对应的实体类路径,配置文件指定包路径可只写类名">
<select id="GetUserByID" parameterType="int" resultType="com.test.springtest.dao.MUser">
select * from `student` where id = #{id}
</select>
<insert
id="saveUser" parameterType="com.test.springtest.User"
useGeneratedKeys="true">
insert into student(NAME,AGE) values (#{name},#{age})
</insert>
</mapper>