SpringBootData JPA introduction
SpringData: SpringData fact that Spring provides a framework for the operation of the data. While only a SpringData JPA SpringData under standard operating data frame based JPA module.
SpringData JPA: JPA-based standard operating data. Simplified operation code persistence layer. Only you need to write the interface can be.
SpringBoot JPA integration SpringData
. 1, introduced maven dependent
plus JPA dependence of the basis of the original SprigBoot in dependence maven
2. application.properties add configuration file
3. The entity class
@Table(name="t_users")
public class Users {
@GeneratedValue(strategy=GenerationType.IDENTITY)//主键生成策略
@Column(name="id")//数据库字段名
private Integer id;
@Column(name="name")
private String name;
@Column(name="age")
private Integer age;
@Column(name="address")
private String address;
@JoinColumn(name ="role_id") //维护一个外键,外键在Users一侧
private Roles roles;
/**
* 参数一 T :当前需要映射的实体
* 参数二 ID :当前映射的实体中的OID的类型
*
*/
public interface UsersRepository extends JpaRepository<Users,Integer> {
测试测试
三、SpringBoot JPA提供的核心接口
1、Repository接口
2、CrudRepository接口
3、PagingAndSortingRepository接口
4、JpaRepository接口
5、JPASpecificationExecutor接口
————————————————
版权声明:本文为CSDN博主「我见青山多抚媚」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_39086296/article/details/90485645