Spring boot整合mybatis
2018-01-23 14:51
357 查看
沿用上篇中使用mybatis generator生成的代码进行整合 打开链接
1 : 修改application.yml配置数据库等信息
server:
port: 8888
spring:
datasource:
name: CloudDB
url: jdbc:mysql://127.0.0.1:3306/cloud?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false
username: root
password: root
#配置使用druid连接池
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
filters: stat
maxActive: 20
initialSize: 1
maxWait: 60000
minIdle: 1
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: select 'x'
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
maxOpenPreparedStatements: 20
#mybatis配置
mybatis:
mapper-locations:
- classpath:mapping/*.xml
#pagehelper插件
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
2 : 在启动类上添加注解
package cn.sh.daniel;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@MapperScan("cn.sh.daniel.mapper") //指定mapper扫描的包路径
public class CloudShopUserserviceHaApplicati
4000
on {
public static void main(String[] args) {
SpringApplication.run(CloudShopUserserviceHaApplication.class, args);
}
}
3 : 新增UserController
4 : 新增service和实现类
5 : 测试方法
新增数据成功,其他方法可以自行验证
1 : 修改application.yml配置数据库等信息
server:
port: 8888
spring:
datasource:
name: CloudDB
url: jdbc:mysql://127.0.0.1:3306/cloud?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false
username: root
password: root
#配置使用druid连接池
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
filters: stat
maxActive: 20
initialSize: 1
maxWait: 60000
minIdle: 1
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: select 'x'
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
maxOpenPreparedStatements: 20
#mybatis配置
mybatis:
mapper-locations:
- classpath:mapping/*.xml
#pagehelper插件
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
2 : 在启动类上添加注解
package cn.sh.daniel;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@MapperScan("cn.sh.daniel.mapper") //指定mapper扫描的包路径
public class CloudShopUserserviceHaApplicati
4000
on {
public static void main(String[] args) {
SpringApplication.run(CloudShopUserserviceHaApplication.class, args);
}
}
3 : 新增UserController
4 : 新增service和实现类
5 : 测试方法
新增数据成功,其他方法可以自行验证
相关文章推荐
- SpringBoot(三):springboot整合mybatis(xml形式)
- springboot整合mybatis注解版与XML配置版
- Spring Boot整合MyBatis
- SpringBoot整合Mybatis多数据源
- Spring Boot 整合 Mybatis 和 MySQL
- Spring + Spring Boot + MyBatis + MongoDB的整合教程
- java鬼混笔记:springboot 7、springboot整合mybatis后再加上druid数据库连接池
- spring boot整合mybatis
- 2.SpringBoot系列-SpringBoot整合MyBatis
- springboot 整合mybatis
- (2)、Spring Boot与Mybatis的整合( 多数据源)
- 解决spring boot整合mybatis时 返回map value为空字段不显示
- [小技巧]关于spring boot 整合mybatis-plus: value为null时不返回的问题。
- springboot整合mybatis(xml+注解)
- springboot整合mybatis中的坑
- SpringBoot+mybatis+jsp整合
- Spring Boot整合MyBatis,附带单元测试
- spring boot 整合mybatis
- JavaEE开发之SpringBoot整合MyBatis以及Thymeleaf模板引擎
- Spring-Boot学习(3)-----Spring-Boot整合mybatis