数据准备
创建Docker
docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7
查看docker内容
$ docker exec -it mysql mysql -uroot -p123456
mysql> CREATE DATABASE test;
mysql>DROP TABLE IF EXISTS `user`;
mysql>CREATE TABLE `user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(128) NOT NULL,
`password` varchar(128) NOT NULL,
PRIMARY KEY (`id`)
)
mysql>INSERT INTO `user` VALUES (1, 'xiaoming', '123456');
mysql>INSERT INTO `user` VALUES (2, 'xiaohong', '654321');
查看最终数据
mysql> use test;
mysql> SELECT id,name,password FROM user;
+----+----------+----------+
| id | name | password |
+----+----------+----------+
| 1 | xiaoming | 123456 |
| 2 | xiaohong | 654321 |
+----+----------+----------+
2 rows in set (0.01 sec)
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
配置菜单
spring:
datasource:
username: root
password: baxiang
url: jdbc:mysql://127.0.0.1:3306/user?useSSL=false
driver-class-name: com.mysql.jdbc.Driver
schema:
- classpath:department.sql
JDBC连接池
druid Filter
JDBC Template
query
queryForObject
queryForList
update
插入修改删除
execute
事务抽象
一致的事务模型
JDBC/Hibernate/myBatis
DataSource/JTA