標籤:整合 debug model .class color com run use bat
一、SpringBoot常見配置
(1)SpingBoot與MyBatis整合時跟蹤SQL語句
log4j: logger: java: sql: ResultSet: TRACE
(2)日誌跟蹤
debug: truelogging: config: classpath:log4j2/log4j2.xml
(3)MyBatis整合:
#mybatis配置mybatis: #配置映射類所在包名 type-aliases-package: com.xx.it.model (資料庫實體物件所在路徑,一般為@Data對象,非Mapper注釋項所在路徑) #配置mapper.xml檔案所在路徑 mapper-location: classpath:com/xx/it/*.xml(非必須項,可以不配)#不需要再配置Spring任何檔案@SpringBootApplication public class Application { SpringApplication.run(Application.class,args); }
Mapper所在路徑不需要配置,系統會自動掃描與Application同級及以下的所有目錄,同時對應的Spring也不需要配置
二、常見錯誤
(1)SpringBoot與MyBatis整合
A.ResultMap與ResultType導致的問題
<resultMap id="sample" type="com.xx.it.SampleVo"> <result property="id" column="id" /> <result property="name" column="name" /> <result property="useYn" column="use_yn" /></resultMap><select id="selectSample" resultMap="sample"> select id,name,useYn from sample where id = #{id}</select><select id="getReply" parameterType="sampleVo" resultType="sample"> select id,name,useYn from sample where id = #{id}</select>
ResultMap:組裝資料庫中結果與實體物件的映射關係(將資料庫中查詢出來的結果映射給實體類)
column:表中欄位名;property:實體類的屬性名稱
Spring Boot常見配置及錯誤