Spring boot中集成mybatis开发环境

spring-boot集成mybatis环境的步骤:

一,在pom.xml中引入mybatis的依赖文件,根据需要也可以引入mybatis分页插件的依赖文件

二,在application.properties配置文件中配置数据源(使用的是阿里开源的数据源)和分页插件的的配置文件

三,在spring-boot的启动类,使用@MapperScan("com.test.mapper")来扫描指定包下的mybatis持久化文件,也就是mybatis的xml文件所在的包;


配置如下:

一,在pom.xml中引入mybatis和,mybatis分页插件依赖,以及阿里数据源依赖文件

             
   
   
            org.mybatis.spring.bootmybatis-spring-boot-starter1.1.1
   
   com.github.pagehelperpagehelper-spring-boot-starter1.1.1
   
   com.alibabadruid1.0.25

二,在Appalication.properties配置文件中配置数据源配置文件,mybatis配置文件,mybatis分页插件配置文件

empty#mysql\u6570\u636E\u5E93\u8FDE\u63A5\u6C60
spring:
    datasource:
        spring.datasource.name: student
        spring.datasource.url: jdbc:mysql://localhost:3306/student
        spring.datasource.username: root
        spring.datasource.password: 
        # \u4F7F\u7528druid\u6570\u636E\u6E90
        spring.datasource.type: com.alibaba.druid.pool.DruidDataSource
        spring.datasource.driver-class-name: com.mysql.jdbc.Driver
        spring.datasource.filters: stat
        spring.datasource.maxActive: 20
        spring.datasource.initialSize: 1
        spring.datasource.maxWait: 60000
        spring.datasource.minIdle: 1
        spring.datasource.timeBetweenEvictionRunsMillis: 60000
        spring.datasource.minEvictableIdleTimeMillis: 300000
        spring.datasource.validationQuery: select 'x'
        spring.datasource.testWhileIdle: true
        spring.datasource.testOnBorrow: false
        spring.datasource.testOnReturn: false
        spring.datasource.poolPreparedStatements: true
        spring.datasource.maxOpenPreparedStatements: 20


#mybatis
mybatis.type-aliases-package=com.decolor.model
mybatis.mapper-locations=classpath:mapper/*.xml



#pagehelper
pagehelper.helperDialect=mysql
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count\=countSql

三,在spring-boot启动类中配置扫描

@SpringBootApplication
@MapperScan("com.decolor.mapper")//扫描指定包下的xml文件
public class Application {
 public static void main(String[] args) {
	SpringApplication.run(Application.class, args);
}
}




猜你喜欢

转载自blog.csdn.net/qq_34125349/article/details/77202227