<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 { }