zoukankan      html  css  js  c++  java
  • SpringBoot JPA

                                                                             -------------------- 剩下的时间不多了,全力做一些自己喜欢的东西

    SpringBoot JPA :

       默认使用的orm 框架是 hirbernate, 所以具备一些常见的hibernate 的功能, 

    不用手写数据库中的表,简单的crud 也不需要自己去写,只需继承一个接口就可以了。

    @Entity
    @Table(name = "AUTH_ROLE")
    public class RoleDO {
        @Id
        private Long id;
        @Column(length = 32)
        private String name;
        @Column(length = 64)
        private String note;
    
        public Long getId() {
            return id;
        }
    
        public void setId(Long id) {
            this.id = id;
        }
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public String getNote() {
            return note;
        }
    
        public void setNote(String note) {
            this.note = note;
        }
    }

     上面的注解都是jpa 所带有的

    package com.yanggaochao.springboot.learn.springbootjpalearn.security.dao;
    
    
    import com.yanggaochao.springboot.learn.springbootjpalearn.security.domain.dao.UserDO;
    import org.springframework.data.jpa.repository.JpaRepository;
    import org.springframework.stereotype.Repository;
    
    /**
     * 用户服务数据接口类
     *
     * @author 杨高超
     * @since 2018-03-12
     */
    
    @Repository
    package com.yanggaochao.springboot.learn.springbootjpalearn.security.dao;
    
    
    import com.yanggaochao.springboot.learn.springbootjpalearn.security.domain.dao.UserDO;
    import org.springframework.data.jpa.repository.JpaRepository;
    import org.springframework.stereotype.Repository;
    
    /**
     * 用户服务数据接口类
     *
     * @author 杨高超
     * @since 2018-03-12
     */
    
    @Repository
    public interface UserDao extends JpaRepository<UserDO, Long> {
    }

    只需要继承上面红色标注的接口就可以了, 其中UserDo 是实体类的名称, long 是 数据表id 的类型

  • 相关阅读:
    【VUE】5.路由导航守卫
    【VUE】4.配置axios发起请求
    【VUE】3.表单操作
    【GIT】命令笔记
    【VUE】2.渲染组件&重定向路由
    【Vue】1.前端项目初始化
    【PYTHON】操作excel笔记
    【Python】python 入门与进阶
    【flask-migrate】:ERROR [root] Error: Target database is not up to date.
    【Flask】学习笔记(一)入门
  • 原文地址:https://www.cnblogs.com/helloqiufei/p/11987091.html
Copyright © 2011-2022 走看看