工程简介
基于springboot的ssm整合
依赖
- lombok
- spring web
- mysql driver
- mybatis framework
<properties>
<java.version>1.8</java.version>
//修改mysql的版本
<mysql.version>5.1.47</mysql.version>
</properties>
driver-class-name: com.mysql.jdbc.Driver
低版本mysql 没有cj
进行mybatis所需的配置
- 将配置文件修改为yaml文件
- 完成mybatis的自定义配置
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/powernodeDB?characterEncoding=utf-8
username: root
password: 12345678
mybatis:
type-aliases-package: com.powernode.springboot.ssm.beans
mapper-locations: classpath:mappers/*Mapper.xml
在启动类配置DAO扫描
- @MapperScan
@MapperScan("com.powernode.springboot.ssm.dao")
//扫描多个文件夹
@MapperScan("com.powernode.springboot.ssm.dao","com.powernode.springboot.ssm.dao")
@SpringBootApplication
@MapperScan("com.powernode.springboot.ssm.dao")
public class SpringbootSsmApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootSsmApplication.class, args);
}
}
整合Druid连接池
在springboot中整合mybatis的时候 默认集成了Hikari连接池
Hikari的效率比Druid效率高
但是得益于Druid提供比较便捷的监控系统
在企业开发中 Druid市场占比很高
2021-05-28 11:33:50.952 INFO 18809 --- [nio-8081-exec-2] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2021-05-28 11:33:51.238 INFO 18809 --- [nio-8081-exec-2] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
- 添加druid的start的依赖
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.10</version>
</dependency>
- 修改配置文件
spring:
datasource:
druid:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/powernodeDB?characterEncoding=utf-8
username: root
password: 12345678
initial-size: 1
min-idle: 1
max-active: 20
2021-05-28 14:28:29.759 INFO 21767 --- [ main] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} inited
网友评论