spring5x data jpa

spring5x data jpa

spring5x-data-jpa This module is extended from the spring5x-base basic module. The spring5x-base module is a very clean spring5.x+springMVC architecture. If you have not built the spring5x-base module, please refer to the spring5x-base module to build

Build the project

New features based on spring5x-base basic module:

  • 1. Spring integrated jpa dependency and configuration
  • 2. Entity class and dao interface layer
  • 3. Unit test (used by jpa)
  • 4. Project complete pom
  • 5. The github and blog addresses of the project

1. Spring integrated jpa dependency and configuration

  • jpa dependency
        <!-- hibernate   -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.4.4.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>5.4.4.Final</version>
        </dependency>
        <!--hibernate jpa , session transaction -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <!--spring-data-jpa-->
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <version>2.1.10.RELEASE</version>
        </dependency>
 
  • jpa configuration

hibernate-jpa.properties

## hibernate 
hibernate.scan.package=com.zja.entity

#  
hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
#hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
#  sql 
hibernate.show_sql=true
#  sql 
hibernate.format_sql=true
#  update none 
hibernate.hbm2ddl.auto=update
#   My_NAME->MyName
hibernate.ejb.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy
#hibernate.ejb.naming_strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
##   SQL 
adapter.show_sql=true
##  
adapter.generate_ddl=true

 

spring-data-jpa.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:jpa="http://www.springframework.org/schema/data/jpa"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/data/jpa https://www.springframework.org/schema/data/jpa/spring-jpa.xsd">

    <!--   -->
    <!--druid.xml  -->
    <import resource="classpath:META-INF/spring/datasource/spring-druid.xml"/>
    <!--c3p0.xml  -->
    <!--<import resource="classpath:META-INF/spring/datasource/spring-c3p0.xml"/>-->

    <!-- -->
    <context:property-placeholder location="classpath:properties/hibernate-jpa.properties" ignore-unresolvable="true"/>

    <!--  JPA , -->
    <bean id="hibernateJpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
        <property name="showSql" value="${adapter.show_sql}"/>
        <property name="generateDdl" value="${adapter.generate_ddl}"/>
        <property name="databasePlatform" value="${hibernate.dialect}"/>
    </bean>

    <!--   Jpa  LocalContainerEntityManagerFactoryBean Spring JPA -->
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <!--   -->
        <property name="dataSource" ref="dataSource"/>
        <!--  Jpa , Hibernate  -->
        <property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter"/>
        <!--  Entity  -->
        <property name="packagesToScan" value="${hibernate.scan.package}"/>
        <!--  JPA Hibernate SQL  -->
        <property name="jpaProperties">
            <props>
                <!-- -->
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                <!-- sql -->
                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                <!--sql -->
                <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
                <!-- none -->
                <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
                <!--   My_NAME->MyName-->
                <prop key="hibernate.ejb.naming_strategy">${hibernate.ejb.naming_strategy}</prop>
            </props>
        </property>
    </bean>

    <!-- dao -->
    <!--<jpa:repositories base-package="com.zja.dao" entity-manager-factory-ref="entityManagerFactory" transaction-manager-ref="transactionManager"/>-->
    <jpa:repositories base-package="com.zja.dao"/>

    <!-- Jpa   -->
    <bean id="transactionManager"  class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>

    <!--XML    -->
    <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>

</beans>

 

1. Modify the data source dataSourceconfiguration refer to the github project, or use your own data source 2. Need to modify the entity class scanning package and the dao interface scanning package path

2. Entity class and dao interface layer

  • Entity class
package com.zja.entity;

import lombok.Data;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;

/**
 * Date: 2019-12-12 16:55
 * Author: zhengja
 * Email: zhengja@dist.com.cn
 * Desc 
 */
@Data
@Entity
@Table(name = "demojpa")
public class DemoJpa implements Serializable {
    @Id
    @Column(name = "id", nullable = false)
    private int id;
    @Column(name = "firstname")
    private String firstName;
    @Column(name = "lastname")
    private String lastName;
    @Column
    private String email;
    private int age;

}


/**
 * @author ZhengJa
 * @description User  
 * @data 2019/10/29
 */
@Data
@Entity
@Table(name = "userentity")
@ApiModel(" ")
public class UserEntity implements Serializable {

    @ApiModelProperty(value = " :mysql ,oracle ")
    @Id
    //@GeneratedValue// HIBERNATE_SEQUENCE
    @Column(name = "id", nullable = false)
    private Long id;
    @ApiModelProperty(" ")
    @Basic(fetch = FetchType.EAGER,optional = false) //null
    @Column(name = "username", nullable = false, length = 225)
    private String userName;
    @ApiModelProperty(" ")
    @Column(name = "age", nullable = true)
    private Integer age;
    @ApiModelProperty(" , ")
    @Column(name = "createtime", nullable = true)
    private Date createTime;
    @ApiModelProperty(" , ")
    @Column(name = "updatetime", nullable = true)
    private Date updateTime;
}

 

dao interface layer DemoJpaRepositories.java

package com.zja.dao;

import com.zja.entity.DemoJpa;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

/**
 * Date: 2019-12-12 17:16
 * Author: zhengja
 * Email: zhengja@dist.com.cn
 * Desc 
 */
public interface DemoJpaRepositories extends JpaRepository<DemoJpa,Integer> {

    //firstName LastName ( )
    DemoJpa findByFirstNameAndLastName(String firstName, String lastName);

    //firstName LastName ( )
    DemoJpa findByLastNameOrFirstName(String lastName,String firstName);

    //firstName < >
    //DemoJpa findByFirstName(String firstName);
    DemoJpa findByFirstNameIs(String firstName);

    //Age age age2 
    List<DemoJpa> findByAgeBetween(Integer age, Integer age2);

    //age 
    List<DemoJpa> findByAgeLessThan(Integer age);

    //age 
    List<DemoJpa> findByAgeLessThanEqual(Integer age);

    //age 
    List<DemoJpa> findByAgeGreaterThan(Integer age);

    //age 
    List<DemoJpa> findByAgeGreaterThanEqual(Integer age);

    //age <LessThan>
    List<DemoJpa> findByAgeAfter(Integer age);

    //age <GreaterThan>
    List<DemoJpa>  findByAgeBefore(Integer age);

    //age 
    List<DemoJpa> findByAgeIsNull();

    //age 
    List<DemoJpa> findByAgeNotNull();

    /**
     *  ,
     *  
     *  
     * DemoJpa findByFirstName(String firstName);
     * @see https://docs.spring.io/spring-data/jpa/docs/2.1.5.RELEASE/reference/html/#jpa.repositories
     */
    DemoJpa findByFirstNameLike(String firstName);

    //
    List<DemoJpa> findByFirstNameNotLike(String firstName);

    //( "M" Jpa M )< >
    List<DemoJpa> findByFirstNameStartingWith(String firstName);

    //( )
    List<DemoJpa> findByFirstNameEndingWith(String firstName);

    //( )
    List<DemoJpa> findByFirstNameContaining(String firstName);

    //age LastName 
    List<DemoJpa> findByAgeOrderByLastName(Integer age);

    //age 
    List<DemoJpa> findByAgeNot(Integer age);

    //age 
    List<DemoJpa> findByAgeIn(List<Integer> age);

}

 

UserEntityDao.java

package com.zja.dao;


import com.zja.entity.UserEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import javax.transaction.Transactional;
import java.util.List;

/**
 * Date: 2019-12-11 17:18
 * Author: zhengja
 * Email: zhengja@dist.com.cn
 * Desc 
 */
//@Repository
public interface UserEntityDao extends JpaRepository<UserEntity,Long>{

    //
    //@Override
    //List<UserEntity> findAll(Sort sort);


    //
    /*@Override
    void deleteInBatch(Iterable<UserEntity> entities);*/

    //
    /*@Override
    void deleteAllInBatch();*/

    /**
     *  @Query  
     *  
     *  UserEntity userName 
     * @param userName  - 
     */
    @Query("select u from UserEntity u where u.userName = :userName")
    UserEntity findUserByUserName(@Param("userName") String userName);

    /**
     *  ?  
     * 1 
     * @param age  
     */
    @Query("select u from UserEntity u where u.age = ?1")
    List<UserEntity> findUserByAge(Integer age);

    /**
     *  
     *   @Query   @Modifying  
     * @param userName  
     * @param newUserName  
     */
    @Transactional
    @Modifying
    @Query(value="update UserEntity u set u.userName=:newUserName where u.userName like %:userName")
    int findByUpdateUserName(@Param("userName") String userName,@Param("newUserName") String newUserName);

    /**
     *  @Query sql nativeQuery true
     *  userentity username 
     * @param userName
     */
    @Query(value = "select * from userentity u where u.username like %?1",nativeQuery = true)
    List<UserEntity> findUserByLikeUserName(String userName);

}

 

3. Unit test (used by jpa)

Test class DemoJpaRepositoriesTest.java

import com.zja.dao.DemoJpaRepositories;
import com.zja.entity.DemoJpa;
import org.junit.Assert;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.web.WebAppConfiguration;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Date: 2019-12-12 17:18
 * Author: zhengja
 * Email: zhengja@dist.com.cn
 * Desc 
 */
@RunWith(JUnitPlatform.class)
@ExtendWith(SpringExtension.class)
@WebAppConfiguration
@ContextConfiguration({"classpath*:META-INF/spring/spring-common.xml"})
public class DemoJpaRepositoriesTest {

    @Autowired
    private DemoJpaRepositories repositories;

    @Test
    public void saveAll() {

        List<DemoJpa> demoJpas = new ArrayList<>();

        for (int i=1;i<10;i++){
            DemoJpa demoJpa = new DemoJpa();
            demoJpa.setId(i);
            demoJpa.setAge(14+i);
            demoJpa.setEmail("126@qq.com");
            demoJpa.setFirstName("May"+i);
            demoJpa.setLastName("Eden"+i);
            demoJpas.add(demoJpa);
        }

        List<DemoJpa> jpas = this.repositories.saveAll(demoJpas);
        System.out.println(jpas);
    }

    @Test
    public void findByFirstNameAndLastName() {
        DemoJpa demoJpa = repositories.findByFirstNameAndLastName("May1", "Eden1");
        System.out.println(demoJpa);
        Assert.assertEquals(demoJpa.getFirstName(),"May1");
    }

    @Test
    public void findByLastNameOrFirstName() {
        DemoJpa demoJpa = repositories.findByLastNameOrFirstName("Eden1", "May1");
        System.out.println(demoJpa);
        //Assert.assertNotEquals(demoJpa.getLastName(),"Eden1");
    }

    @Test
    public void findByFirstNameIs() {
        DemoJpa demoJpa = repositories.findByFirstNameIs("May2");
        System.out.println(demoJpa);
        //Assert.assertNull(demoJpa);
    }

    @Test
    public void findByAgeBetween() {
        List<DemoJpa> demoJpaList = repositories.findByAgeBetween(15, 17);
        System.out.println(demoJpaList);
        Assert.assertEquals(3,demoJpaList.size());
    }

    @Test
    public void findByAgeLessThan() {
        List<DemoJpa> demoJpaList = repositories.findByAgeLessThan(17);
        System.out.println(demoJpaList);
        Assert.assertEquals(2,demoJpaList.size());
    }

    @Test
    public void findByAgeLessThanEqual() {
        List<DemoJpa> demoJpaList = repositories.findByAgeLessThanEqual(17);
        System.out.println(demoJpaList);
        Assert.assertEquals(3,demoJpaList.size());
    }

    @Test
    public void findByAgeGreaterThan() {
        List<DemoJpa> demoJpaList = repositories.findByAgeGreaterThan(17);
        System.out.println(demoJpaList);
        //Assert.assertEquals(2,demoJpaList.size());
    }

    @Test
    public void findByAgeGreaterThanEqual() {
        List<DemoJpa> demoJpaList = repositories.findByAgeGreaterThanEqual(17);
        System.out.println(demoJpaList);
        //Assert.assertEquals(3,demoJpaList.size());
    }

    @Test
    public void findByAgeAfter() {
        List<DemoJpa> demoJpaList = repositories.findByAgeAfter(17);
        System.out.println(demoJpaList);
        //Assert.assertEquals(2,demoJpaList.size());
    }

    @Test
    public void findByAgeBefore() {
        List<DemoJpa> demoJpaList = repositories.findByAgeBefore(17);
        System.out.println(demoJpaList);
        //Assert.assertEquals(2,demoJpaList.size());
    }

    @Test
    public void findByAgeIsNull() {
        List<DemoJpa> demoJpaList = repositories.findByAgeIsNull();
        System.out.println(demoJpaList);
        //Assert.assertEquals(0,demoJpaList.size());
    }

    @Test
    public void findByAgeNotNull() {
        List<DemoJpa> demoJpaList = repositories.findByAgeNotNull();
        System.out.println(demoJpaList);
        //Assert.assertEquals(5,demoJpaList.size());
    }

    @Test
    public void findByFirstNameLike() {
        DemoJpa demoJpa = repositories.findByFirstNameLike("May");
        System.out.println(demoJpa);
        //Assert.assertNotNull(demoJpa);
    }

    @Test
    public void findByFirstNameNotLike() {

    }

    @Test
    public void findByFirstNameStartingWith() {
        List<DemoJpa> demoJpaList = repositories.findByFirstNameStartingWith("May");
        System.out.println(demoJpaList);
        //Assert.assertEquals(2,demoJpaList.size());
    }

    @Test
    public void findByFirstNameEndingWith() {
        List<DemoJpa> demoJpaList = repositories.findByFirstNameEndingWith("May");
        System.out.println(demoJpaList);
        //Assert.assertEquals(0,demoJpaList.size());
    }

    @Test
    public void findByFirstNameContaining() {
        List<DemoJpa> demoJpaList = repositories.findByFirstNameContaining("May");
        System.out.println(demoJpaList);
        //Assert.assertEquals(0,demoJpaList.size());
    }

    @Test
    public void findByAgeOrderByLastName() {
        List<DemoJpa> demoJpaList = repositories.findByAgeOrderByLastName(18);
        for (DemoJpa demoJpaL : demoJpaList){
            System.out.println(" "+demoJpaL.toString());
            //log.info(" "+demoJpaL.toString());
        }
    }

    @Test
    public void findByAgeNot() {
        List<DemoJpa> demoJpaList = repositories.findByAgeNot(20);
        System.out.println(demoJpaList);
        //Assert.assertEquals(5,demoJpaList.size());
    }

    @Test
    public void findByAgeIn() {
        List<DemoJpa> demoJpaList = repositories.findByAgeIn(Arrays.asList(15, 16));
        System.out.println(demoJpaList);
        //Assert.assertEquals(2,demoJpaList.size());
    }
}

 

UserEntityDaoTest.java

import com.zja.dao.UserEntityDao;
import com.zja.entity.UserEntity;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.web.WebAppConfiguration;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Stream;

/**
 * Date: 2019-12-12 17:49
 * Author: zhengja
 * Email: zhengja@dist.com.cn
 * Desc 
 */
@RunWith(JUnitPlatform.class)
@ExtendWith(SpringExtension.class)
@WebAppConfiguration
@ContextConfiguration({"classpath*:META-INF/spring/spring-common.xml"})
public class UserEntityDaoTest {

    @Autowired
    private UserEntityDao userEntityDao;

    //
    @Test
    public void saveAll(){
        List<UserEntity> userEntities = new ArrayList<>();

        for (int i=1;i<10;i++){

            UserEntity userEntity = new UserEntity();
            userEntity.setId(i+0L);
            userEntity.setUserName(" "+i);
            userEntity.setAge(14+i);
            userEntity.setCreateTime(new Date());
            userEntity.setUpdateTime(new Date());

            userEntities.add(userEntity);
        }

        List<UserEntity> jpas = this.userEntityDao.saveAll(userEntities);
        System.out.println(jpas);
    }

    //
    @Test
    public void findAll(){
        List<UserEntity> userEntityList = this.userEntityDao.findAll();
        System.out.println(userEntityList);
    }

    //( )
    @Test
    public void findByUpdateUserName(){
        int updateResult = this.userEntityDao.findByUpdateUserName(" 2"," ");
        System.out.println(updateResult);
        //like 
        UserEntity byUserName = this.userEntityDao.findUserByUserName(" ");
        System.out.println(byUserName);
    }

    //age 
    @Test
    public void findUserByAge(){
        List<UserEntity> userEntityList = this.userEntityDao.findUserByAge(15);
        System.out.println(userEntityList);
    }

    //like 
    @Test
    public void findUserByLikeUserName(){
        List<UserEntity> userEntityList = this.userEntityDao.findUserByLikeUserName(" %");
        System.out.println(userEntityList);
    }

    //
    @Test
    public void pageable(){
        Sort sort =new Sort(Sort.Direction.DESC,"age");
        Pageable pageable = PageRequest.of(2,3,sort);
        Page<UserEntity> entityPage = userEntityDao.findAll(pageable);
        List<UserEntity> userEntityList = entityPage.getContent();
        System.out.println(userEntityList);
        System.out.println(" "+entityPage.getSize());
        System.out.println(" "+entityPage.getNumber());
        System.out.println(" "+entityPage.getSort());
        System.out.println(" "+entityPage.getTotalElements());
        System.out.println(" "+entityPage.getTotalPages());
    }

    //
    @Test
    public void sort(){
        Sort sort =new Sort(Sort.Direction.ASC,"age");
        List<UserEntity> userEntityList = userEntityDao.findAll(sort);
        System.out.println(userEntityList);
    }

    //
    @Test
    public void deleteInBatch(){
        List<UserEntity> userEntities = new ArrayList<>();

        for (int i=1;i<5;i++){

            UserEntity userEntity = new UserEntity();
            userEntity.setId(i+0L);
            userEntity.setUserName(" "+i);
            userEntity.setAge(14+i);
            userEntity.setCreateTime(new Date());
            userEntity.setUpdateTime(new Date());

            userEntities.add(userEntity);
        }
        //id 
        userEntityDao.deleteInBatch(userEntities);
        //
        List<UserEntity> userEntityList = userEntityDao.findAll();
        System.out.println(userEntityList);
    }

    //
    @Test
    public void deleteAllInBatch(){
        userEntityDao.deleteAllInBatch();
        //
        List<UserEntity> userEntityList = userEntityDao.findAll();
        System.out.println(userEntityList);
    }
}

 

4. Project complete pom

pom

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.zja</groupId>
        <artifactId>spring5x</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <groupId>com.zja</groupId>
    <artifactId>spring5x-data-jpa</artifactId>
    <packaging>war</packaging>

    <name>spring5x-data-jpa</name>

    <!-- spring5.x-base spring5.x -->
    <properties>
        <!--spring5.x  jdk1.8 -->
        <spring.version>5.0.9.RELEASE</spring.version>
        <!--jdk  >=1.8-->
        <jdk.version>1.8</jdk.version>
        <!--maven  -->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.plugin.version>3.6.0</maven.compiler.plugin.version>
        <mavne.surefire.plugin.version>2.19.1</mavne.surefire.plugin.version>
        <maven-war-plugin.version>2.6</maven-war-plugin.version>
        <servlet.version>4.0.1</servlet.version>

        <!--junit5-->
        <junit5.version>5.1.0</junit5.version>
        <junit5-platform.version>1.1.0</junit5-platform.version>
    </properties>

    <dependencies>
        <!--spring Start-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-oxm</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <!-- spring jdbc jar tx jdbc -->
        <!-- spring jar tx -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <!-- spring web   spring MVC jar webmvc -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring.version}</version>
            <scope>test</scope>
        </dependency>
        <!--spring End-->

        <!--servlet-api  web -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>${servlet.version}</version>
            <scope>provided</scope>
        </dependency>

        <!--jackson    Jackson  -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.9.4</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.9.10.1</version>
            <exclusions>
                <exclusion>
                    <artifactId>jackson-annotations</artifactId>
                    <groupId>com.fasterxml.jackson.core</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>jackson-core</artifactId>
                    <groupId>com.fasterxml.jackson.core</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.9.4</version>
        </dependency>

        <!-- -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>

        <!-- junit5 -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>${junit5.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-runner</artifactId>
            <version>${junit5-platform.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-console-standalone</artifactId>
            <version>${junit5-platform.version}</version>
            <scope>test</scope>
        </dependency>

        <!-- -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-nop</artifactId>
            <version>1.7.28</version>
        </dependency>

        <!--  lombok JavaBean get set toString hashCode equals   -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.2</version>
            <scope>provided</scope>
            <optional>true</optional>
        </dependency>

        <!--spring5.x  swagger2-->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
            <exclusions>
                <exclusion>
                    <artifactId>jackson-annotations</artifactId>
                    <groupId>com.fasterxml.jackson.core</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>spring-context</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>spring-beans</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>spring-aop</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>slf4j-api</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>
        <!-- swagger2 2.9.x  java.lang.NumberFormatException: For input string: ""-->
        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-annotations</artifactId>
            <version>1.5.22</version>
        </dependency>
        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-models</artifactId>
            <version>1.5.22</version>
        </dependency>

        <!--mysql  -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.13</version>
        </dependency>
        <!--oracle  -->
        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>11.2.0.3</version>
        </dependency>

        <!--druid  -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.1.20</version>
        </dependency>
        <!--c3p0  -->
        <dependency>
            <groupId>com.mchange</groupId>
            <artifactId>c3p0</artifactId>
            <version>0.9.5.2</version>
        </dependency>
        <!--hibernate-c3p0  -->
        <!--<dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-c3p0</artifactId>
            <version>5.3.10.Final</version>
        </dependency>-->

        <!-- hibernate   -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.4.4.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>5.4.4.Final</version>
        </dependency>
        <!--hibernate jpa , session transaction -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <!--spring-data-jpa-->
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <version>2.1.10.RELEASE</version>
            <exclusions>
                <exclusion>
                    <artifactId>spring-beans</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>spring-aop</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>spring-context</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>spring-core</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>spring-jdbc</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>spring-tx</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>slf4j-api</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>

    </dependencies>

    <build>
        <finalName>spring5x-data-jpa</finalName>
        <plugins>
            <!--maven -->
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven.compiler.plugin.version}</version>
                <configuration>
                    <!-- -->
                    <source>${jdk.version}</source>
                    <!--.class -->
                    <target>${jdk.version}</target>
                    <!-- -->
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>
            <!-- -->
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${mavne.surefire.plugin.version}</version>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

 

5. The project's github and Jianshu blog address

github:

Blog: