- properties文件下
spring.datasource.username=root
spring.datasource.password=XXX
spring.datasource.ur1=jdbc:mysq1://localhost:3306/XXX?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8
spring.datasource.driver-class-name-com.mysql.cj.jdbc.Driver
#整合mybatis
mybatis.type-aliases-package=自己的实体类包的地址
mybatis.mapper-locations=classpath:XXX(自己的mapper映射文件放的位置,注意前面有classpath:)
- mapper 接口文件
@Mapper
@Repository
public interface UserMapper {
List<User> queryUserList();
}
- 对用的Mapper映射文件
<?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="mapper接口的位置">
#SQL语句 useCache="ture"是开启缓存
<select id="XXX" resultType="XXX" useCache="ture">
select * from xxx;
</select>
</mapper>
然后就可以在控制器中调用