zoukankan      html  css  js  c++  java
  • Spring Data JPA

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

  • 相关阅读:
    bootstrapValidator重新校验/全选回显
    mybatis遍历map参数查询
    location.href传json字符串
    springmvc异步处理
    intellIJ IDEA学习笔记3
    intellIJ IDEA学习笔记2
    intellIJ IDEA学习笔记
    maven国内镜像
    Docker版本Jenkins的使用
    Docker容器网络
  • 原文地址:https://www.cnblogs.com/Lemonades/p/11724782.html
Copyright © 2011-2022 走看看