您的位置:首页 > 编程语言 > Java开发

mybatis spring boot starter配置

2017-05-15 00:00 375 查看
##maven

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

##application.yml配置

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

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配置

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

##doc

mybatis-configuration
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Spring Boot MyBatis