别人的详细笔记: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

01-04 18:05