Spring data jpa 의 대량 조회 와 대량 삽입 및 상용 작업

4789 단어 자바springbootJPA
때때로 우 리 는 데이터베이스 에 대량의 데 이 터 를 삽입 해 야 한다.만약 하나하나 삽입 하면 매우 느 릴 것 이다
그래서 대량 삽입 을 고려 할 수 있 습 니 다.
사실 간단 해 요.기본 save()방법 만 사용 하면 돼 요.
현재 student 실체 클래스 가 있다 고 가정 합 니 다.  우 리 는 전체 학구 5000 명의 학생 들 의 정 보 를 한 번 에 삽입 해 야 한다.
4.567913.저 는 실체 류 에 주 해 를 달 지 않 았 습 니 다.실제 사용 할 때 스스로 주의 하 세 요.저 는 demo 만 쓰 고 실행 하지 않 았 습 니 다.
 
  
package com.chunying.boke.bean;

/**
 * @author chunying
 */
public class Student {

    private Integer studentID;
    private String name;
    private Integer age;

    public Integer getStudentID() {
        return studentID;
    }

    public void setStudentID(Integer studentID) {
        this.studentID = studentID;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }
}
package com.chunying.boke.dao;

import com.chunying.boke.bean.Student;
import org.springframework.data.jpa.repository.JpaRepository;

/**
 * @author chunying
 */
public interface StudentDao extends JpaRepository<Student, Integer> {
}

대량 조회 에 대해 서 는 일반적인 JPA 작업 에 대응 하 는 방법 명 을 열거 합 니 다.
키워드
방법 이름
sql where 자구
And
findByNameAndPwd
where name= ? and pwd =?
Or
findByNameOrSex
where name= ? or sex=?
Is,Equals
findById,findByIdEquals
where id= ?
Between
findByIdBetween
where id between ? and ?
LessThan
findByIdLessThan
where id < ?
LessThanEquals
findByIdLessThanEquals
where id <= ?
GreaterThan
findByIdGreaterThan
where id > ?
GreaterThanEquals
findByIdGreaterThanEquals
where id > = ?
After
findByIdAfter
where id > ?
Before
findByIdBefore
where id < ?
IsNull
findByNameIsNull
where name is null
isNotNull,NotNull
findByNameNotNull
where name is not null
Like
findByNameLike
where name like ?
NotLike
findByNameNotLike
where name not like ?
StartingWith
findByNameStartingWith
where name like '?%'
EndingWith
findByNameEndingWith
where name like '%?'
Containing
findByNameContaining
where name like '%?%'
OrderBy
findByIdOrderByXDesc
where id=? order by x desc
Not
findByNameNot
where name <> ?
In
findByIdIn(Collection> c)
where id in (?)
NotIn
findByIdNotIn(Collection> c)
where id not  in (?)
True
findByAaaTue
where aaa = true
False
findByAaaFalse
where aaa = false
IgnoreCase
findByNameIgnoreCase
where UPPER(name)=UPPER(?)
예:예 를 들 어 어떤 연령 대의 학생 들 을 대량으로 조회 해 야 한다.
List findByAgeIN(Coollection<> c);

좋은 웹페이지 즐겨찾기