Spring boot中集成mybatis开发环境

来源:互联网 发布:淘宝上nike官方旗舰店 编辑:程序博客网 时间:2024/05/21 09:17

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.boot    mybatis-spring-boot-starter    1.1.1    com.github.pagehelper    pagehelper-spring-boot-starter    1.1.1              com.alibaba  druid  1.0.25

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

empty#mysql\u6570\u636E\u5E93\u8FDE\u63A5\u6C60spring:    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#mybatismybatis.type-aliases-package=com.decolor.modelmybatis.mapper-locations=classpath:mapper/*.xml#pagehelperpagehelper.helperDialect=mysqlpagehelper.reasonable=truepagehelper.supportMethodsArguments=truepagehelper.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);}}




原创粉丝点击