06_資料代理
阿新 • • 發佈:2021-10-26
整合SpringBoot-JPA
-
匯入依賴:
- spring-boot-starter-data-jpa
- mysql-connector-java
-
配置資料庫連線,jpa的表對映關係等
spring: datasource: username: root password: 123456 url: jdbc:mysql://localhost:3306/lgf driver-class-name: com.mysql.jdbc.Driver jpa: database: mysql show-sql: true generate-ddl: true hibernate: ddl-auto: update naming: physical-strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy logging: level: com.cth.dao: debug
-
實體類配置對應欄位名稱
import javax.persistence.*; @Entity @Table() public class Users { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") private Integer id; private String name; private Integer age; private Long phone; }
-
dao介面繼承 JpaRepository 介面
public interface UserDao extends JpaRepository<Users,Integer> {}
-
正常的MVC操作流程