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("
    
    -------------------------------------------------" +
                    "-------------------------------------
    ");
        }
    }
    

      

  • 相关阅读:
    IIS7.5 HTTP 错误 500 调用loadlibraryex失败的解决方法
    VB6.0 excel 导入和导出
    SQL 实现 成绩表形式的转换
    计算月初和月末,年初和年末的日期
    一篇文章学LINQ(原创)
    浙江省仙居县发现罕见丹霞地貌大型“天坑”
    浙江省仙居县发现特大型丹霞地貌洞穴
    EFUpdate
    163邮件出错:不允许使用邮箱名称。 服务器响应为: authentication is required,smtp7,C8CowEDpS0+Uke9VvSmXBg--.546S2 1441763733
    vmware 安装dos注意
  • 原文地址:https://www.cnblogs.com/Answer1215/p/14147638.html
Copyright © 2011-2022 走看看