1、添加依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
2、实体类
package com.example.springdatamysql.Entitle;
import lombok.Data;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@Data
@Entity
@Table(name="company_test")
public class Company {
@Id
@GeneratedValue
private Integer id;
private Long Code;
private String Company;
private Long Number;
private String workshop;
}
3、配置文件
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://xxxxxxxxx:3306/xxxxxxxxx?useUnicode=true&characterEncoding=UTF-8
spring.datasource.username=root
spring.datasource.password=xxxxxxx
spring.jpa.show-sql= true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.jackson.serialization.indent_output=false
4、运行程序即可