springboot集成JPA
集成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操作流程

浙公网安备 33010602011771号