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.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\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);
}
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值