zoukankan      html  css  js  c++  java
  • [Java Spring Data] JapRepository

    All features of CrudRepository plus:

    • void flush();
    • saveAndFlush()
    • delteInBatch()
    • delteAllInBatch()
    package com.example.university.repo;
    
    import com.example.university.domain.Department;
    import org.springframework.data.jpa.repository.JpaRepository;
    
    /**
     * DataSource Management for the Departments at the University.
     *
     * Created by maryellenbowman
     */
    public interface DepartmentRepository extends JpaRepository<Department, Integer> {
    
    }
    

      

    test:

    package com.example.university;
    
    import com.example.university.domain.Department;
    import com.example.university.repo.DepartmentRepository;
    import org.junit.After;
    import org.junit.Before;
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.boot.test.context.SpringBootTest;
    import org.springframework.test.context.junit4.SpringRunner;
    
    
    /**
     * Demonstrate JPA Repository methods with DepartmentRepository
     * <p>
     * Created by maryellenbowman
     */
    
    @RunWith(SpringRunner.class)
    @SpringBootTest
    public class JpaRepositoryDemo {
        @Autowired
        private DepartmentRepository departmentRepository;
        /**
         * Exercise JPA Repository methods.
         */
        @Test
        public void runJpaRepositoryMethods() {
    
            departmentRepository.save(new Department("Humanities"));
            departmentRepository.flush();
    
            departmentRepository.saveAndFlush(new Department("Fine Arts"));
    
            departmentRepository.save(new Department("Social Science"));
    
            System.out.println("
    *************3 Departments*************");
            departmentRepository.findAll().forEach(System.out::println);
    
            departmentRepository.deleteInBatch(
                    departmentRepository.findAll().subList(0,1));
    
            System.out.println("
    *************1 Less Departments*************");
            departmentRepository.findAll().forEach(System.out::println);
            departmentRepository.deleteAllInBatch();
            System.out.println("
    *************Zero Departments*************");
            departmentRepository.findAll().forEach(System.out::println);
    
        }
        @Before
        @After
        public void banner() {
            System.out.println("
    
    -------------------------------------------------" +
                    "-------------------------------------
    ");
        }
    }
    

      

  • 相关阅读:
    定时任务(收集)
    命令学习(收集)
    查看进程运行时间
    Linux 中挂载 ISO 文件
    9.已知三边计算三角形的面积公式
    8.输入一个大写字母,要求小写字母输出
    1.输出三个数中的最大值
    2.依次从大到小输出三个数
    3.计算1+2+3+....100=?
    4.计算1*2*3*4........*100=?
  • 原文地址:https://www.cnblogs.com/Answer1215/p/14147638.html
Copyright © 2011-2022 走看看