<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.2</version>
</dependency>
#整合mybatis,设置别名,识别mapper文件
mybatis:
# 扫描包
type-aliases-package: com.test
# mapper文件扫描
mapper-locations: classpath:mapper/*.xml
@Mapper
public interface UserTestMapper {
int userAgeAddOne(@Param("id") String id,@Param("version") int version);
@Select("select * from test_user")
List<TestUser> findAll();
@Select("select * from test_user where id = #{id}")
TestUser findById(@Param("id") String id);
}
<?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.test.mysql.mapper.UserTestMapper">
<update id="userAgeAddOne" parameterType="String">
update test_user set age=age+1,version=version+1 where id=#{id} and version=#{version};
</update>
</mapper>