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

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 : 测试方法





新增数据成功,其他方法可以自行验证
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: