要使用mybatis
時需要在application.yml
中配置一下這幾個東西的位置,它才能正常幹活。
# MyBatis
mybatis:
# 搜索指定包別名 (實體類所在的位置)
typeAliasesPackage: com.example.demo.entity
# 配置mapper的掃描,找到所有的mapper.xml映射文件
mapperLocations: classpath*:mapper/**/*Mapper.xml
# 如果使用某些代碼生成工具,也可能默認以Dao.xml結尾命名
# mapperLocations: classpath*:mapper/**/*Dao.xml
# 加載全局的配置文件(如果有需要可以加上)
configLocation: classpath:mybatis/mybatis-config.xml
# Sql日誌輸出
logging:
level:
com.example.demo.mapper: trace # *Mapper.java 文件所在的包路徑
上面配置了全局配置,這裏展示一下:E:\demo\src\main\resources\mybatis\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>
<settings>
<setting name="cacheEnabled" value="true" /> <!-- 全局映射器啓用緩存 -->
<setting name="useGeneratedKeys" value="true" /> <!-- 允許 JDBC 支持自動生成主鍵 -->
<setting name="defaultExecutorType" value="REUSE" /> <!-- 配置默認的執行器 -->
<setting name="logImpl" value="SLF4J" /> <!-- 指定 MyBatis 所用日誌的具體實現 -->
<setting name="mapUnderscoreToCamelCase" value="true" /> <!-- 駝峯式命名 -->
</settings>
</configuration>