zoukankan      html  css  js  c++  java
  • Spring boot jpa 底层封装

    pom:

    <!-- https://mvnrepository.com/artifact/javax.persistence/javax.persistence-api -->
    <dependency>
    <groupId>javax.persistence</groupId>
    <artifactId>javax.persistence-api</artifactId>
    <version>2.2</version><!--$NO-MVN-MAN-VER$-->
    </dependency>

    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <!--百度搜索-->

    1.BaseDao

    import org.springframework.data.jpa.repository.JpaRepository;
    import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
    import org.springframework.data.repository.NoRepositoryBean;

    @NoRepositoryBean
    public interface BaseRepo<T> extends JpaRepository<T,Integer>,JpaSpecificationExecutor<T>{

    }

    2.BaseEntity

    import java.io.Serializable;
    import javax.persistence.MappedSuperclass;

    @MappedSuperclass
    public class BaseEntity implements Serializable
    {
    private static final long serialVersionUID = 5316912770609152144L;

    }

    3.BaseService

    import javax.annotation.Resource;
    import javax.persistence.EntityManager;
    import javax.persistence.PersistenceContext;
    import javax.persistence.criteria.CriteriaBuilder;
    import javax.persistence.criteria.CriteriaQuery;
    import javax.persistence.criteria.Predicate;
    import javax.persistence.criteria.Root;
    import org.springframework.data.jpa.domain.Specification;
    import org.springframework.transaction.annotation.Transactional;

    /**
    * 底层封装Service
    * 提供一些基本操作
    * @author x_luwl
    *
    */
    @Transactional(rollbackFor = Exception.class)
    public class BaseService<T extends BaseRepo<D>, D extends BaseEntity> {

    private T dao;

    protected void setDao(T dao) {
    this.dao = dao;
    }
    public T getDao() {
    return this.dao;
    }

    @Resource
    @PersistenceContext
    private EntityManager entityManager;

    }

  • 相关阅读:
    行测-民法典
    行测-中心理解
    行测-资料分析
    行测-数量关系
    行测-三视图、截面图、立体拼合
    行测-加强题型
    C# Unity游戏开发——Excel中的数据是如何到游戏中的 (四)2018.4.3更新
    UGUI batch 规则和性能优化
    Unity 绘图性能优化
    Unity UGUI —— 鼠标穿透UI问题(Unity官方的解决方法)
  • 原文地址:https://www.cnblogs.com/Sora-L/p/9365026.html
Copyright © 2011-2022 走看看