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 的类型

 

 

posted on 2019-12-05 09:20  黄山一叶  阅读(475)  评论(0编辑  收藏  举报