5、数据库方面的操作
- 使用数据库首先要pom文件当中添加两个依赖
- mysql-connector-java
- spring-boot-starter-data-jpa
- 然后创建数据实体
- 配置yml文件
- 创建数据库
- dbgirl
![](https://images2018.cnblogs.com/blog/1345806/201803/1345806-20180326103550497-2063163602.png)
![](https://images2018.cnblogs.com/blog/1345806/201803/1345806-20180326103551730-1317904632.png)
![](https://images2018.cnblogs.com/blog/1345806/201803/1345806-20180326103553767-142434701.png)
package com.girl;
import org.springframework.data.annotation.Id;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
/**
* Created by sunnyangzs on 2018/3/26.
*/
@Entity
public class Girl {
@javax.persistence.Id
@GeneratedValue
private Integer id;
private Integer age;
private String cupSize;
public Girl() {
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public String getCupSize() {
return cupSize;
}
public void setCupSize(String cupSize) {
this.cupSize = cupSize;
}
}
x
50
1
package com.girl;
2
3
import org.springframework.data.annotation.Id;
4
5
import javax.persistence.Entity;
6
import javax.persistence.GeneratedValue;
7
8
/**
9
* Created by sunnyangzs on 2018/3/26.
10
*/
11
12
13
@Entity
14
public class Girl {
15
@javax.persistence.Id
16
@GeneratedValue
17
private Integer id;
18
19
private Integer age;
20
21
private String cupSize;
22
23
public Girl() {
24
}
25
26
public Integer getId() {
27
return id;
28
}
29
30
public void setId(Integer id) {
31
this.id = id;
32
}
33
34
public Integer getAge() {
35
return age;
36
}
37
38
public void setAge(Integer age) {
39
this.age = age;
40
}
41
42
public String getCupSize() {
43
return cupSize;
44
}
45
46
public void setCupSize(String cupSize) {
47
this.cupSize = cupSize;
48
}
49
}
50
spring:
profiles:
active: dev
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/dbgirl
username: root
password: nowcoder
jpa:
hibernate:
ddl-auto: create
show-sql: true
1
16
1
spring:
2
profiles:
3
active: dev
4
5
datasource:
6
driver-class-name: com.mysql.jdbc.Driver
7
url: jdbc:mysql://127.0.0.1:3306/dbgirl
8
username: root
9
password: nowcoder
10
11
jpa:
12
hibernate:
13
ddl-auto: create
14
show-sql: true
15
16