<dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.2.1</version> </dependency>
spring: datasource: url: jdbc:postgresql://localhost:5432/demo driverClassName: org.postgresql.Driver username: postgres password: postgres validation-query: SELECT 1 test-while-idle: true test-on-borrow: true mybatis: config-locations: classpath:mybatis/mybatis-config.xml mapper-locations: classpath:mybatis/mapper/*.xml configuration: map-underscore-to-camel-case: true default-fetch-size: 50 default-statement-timeout: 10 auto-mapping-unknown-column-behavior: WARNING
配置項
mybatis-spring-boot-autoconfigure-1.2.1-sources.jar!/org/mybatis/spring/boot/autoconfigure/MybatisProperties.javahtml
指定mybatis-config.xml的位置java
指定mapper的xml的位置spring
指定別名的包,能夠多個,逗號分隔sql
指定handler的掃描碼路徑數據庫
嵌套的配置,具體詳見mybatis-3.4.4-sources.jar!/org/apache/ibatis/session/Configuration.javaapache
- defaultStatementTimeout 設置超時時間,它決定驅動等待數據庫響應的秒數。 - defaultFetchSize 爲驅動的結果集獲取數量(fetchSize)設置一個提示值。此參數只能夠在查詢設置中被覆蓋。 - mapUnderscoreToCamelCase 是否開啓自動駝峯命名規則(camel case)映射,即從經典數據庫列名 A_COLUMN 到經典 Java 屬性名 aColumn 的相似映射。 - autoMappingUnknownColumnBehavior 指定發現自動映射目標未知列(或者未知屬性類型)的行爲。 - NONE: 不作任何反應 - WARNING: 輸出提醒日誌 ('org.apache.ibatis.session.AutoMappingUnknownColumnBehavior' 的日誌等級必須設置爲 WARN) - FAILING: 映射失敗 (拋出 SqlSessionException)
@MapperScan("com.codecraft.dao") @Configuration public class MybatisConfig { }