Spring-Boot 数据库连接以及class建表
提前在pom.xml文件中添加:jpa,mysql资源
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency> <dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
数据库连接:
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/dbgirl
username: root
password: root
jpa:
hibernate:
ddl-auto: create //每次程序运行时都建新建一个girl表:如果原来有就删除原来的表,再建一个新的
show-sql: true
create:
update:只进行更新
create-drop:才程序停下来就会删掉表
none:什么都不做
validate:验证表中与类中的,不一致则会报错
写一个class文件:
package com.girl; import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id; @Entity
public class girl { @Id
@GeneratedValue
private Integer id;
private String cupSize;
private Integer age; public girl() {
} public Integer getId() {
return id;
} public void setId(Integer id) {
this.id = id;
} public String getCupSize() {
return cupSize;
} public void setCupSize(String cupSize) {
this.cupSize = cupSize;
} public Integer getAge() {
return age;
} public void setAge(Integer age) {
this.age = age;
}
}