mybatis spring boot starter配置

##mavenhtml

<dependency>
			<groupId>org.mybatis.spring.boot</groupId>
			<artifactId>mybatis-spring-boot-starter</artifactId>
			<version>1.2.1</version>
		</dependency>

##application.yml配置java

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.javaspring

  • configLocation 指定mybatis-config.xml的位置
  • mapperLocations 指定mapper的xml的位置
  • typeAliasesPackage 指定別名的包,能夠多個,逗號分隔
  • typeHandlersPackage 指定handler的掃描碼路徑
  • configuration 嵌套的配置,具體詳見mybatis-3.4.4-sources.jar!/org/apache/ibatis/session/Configuration.java
    • defaultStatementTimeout 設置超時時間,它決定驅動等待數據庫響應的秒數。
    • defaultFetchSize 爲驅動的結果集獲取數量(fetchSize)設置一個提示值。此參數只能夠在查詢設置中被覆蓋。
    • mapUnderscoreToCamelCase 是否開啓自動駝峯命名規則(camel case)映射,即從經典數據庫列名 A_COLUMN 到經典 Java 屬性名 aColumn 的相似映射。
    • autoMappingUnknownColumnBehavior 指定發現自動映射目標未知列(或者未知屬性類型)的行爲。
      • NONE: 不作任何反應
      • WARNING: 輸出提醒日誌 ('org.apache.ibatis.session.AutoMappingUnknownColumnBehavior' 的日誌等級必須設置爲 WARN)
      • FAILING: 映射失敗 (拋出 SqlSessionException)

##java配置sql

@MapperScan("com.codecraft.dao")
@Configuration
public class MybatisConfig {
}

##doc數據庫

相關文章
相關標籤/搜索