首页 > 编程语言 > 详细

Spring Data JPA

时间:2019-11-02 21:43:57      阅读:71      评论:0      收藏:0      [点我收藏+]

别人的详细笔记:https://www.jianshu.com/p/c23c82a8fcfc

bojo

@Entity
@Table(name = "tb_user")
@Data
public class User {

    @Id
    @GenericGenerator(name = "idGenerator", strategy = "uuid")
    @GeneratedValue(generator = "idGenerator")
    private String id;

    @Column(name = "username", unique = true, nullable = false, length = 64)
    private String username;

    @Column(name = "password", nullable = false, length = 64)
    private String password;

    @Column(name = "email", length = 64)
    private String email;

}

  

Repository

  是一个空接口,如果继承该接口,会被加到 持久化的Bean 里边。可以使用@RepositoryDefinition(domainClass = ProductCategory.class,idClass = Integer.class) 替换。

 Repository 里边的方法命名是有语法规则的,并且支持级联属性。

 技术分享图片

 技术分享图片

                                   *图片来源尚硅谷 springdata课程笔记

 @Query 注解:

  不使用上面的命名方式,自己定义SQL语句。

 

前面的都是在说查询方法,那么增删改查呢?    

   在@Query上面加上@Modifying注解。同时要配置 事务 ,通常在service层,里边调用dao的方法,上写@Transaction注解( Repository接口里边的事务只允许 只读,所以到service添加事务)。

    注:可以通过@Query自定义的 JPQL 完成 更新update 和 删除delete 操作,但是不支持 插入insert 操作

 

 

 

 

 

a

Spring Data JPA

原文:https://www.cnblogs.com/Lemonades/p/11724782.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!