SpringBoot + JPA EntityManager 实现batch 增删
SpringBoot + JPA 实现batch 增删,提高效率
import java.util.List; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import javax.transaction.Transactional; import org.springframework.stereotype.Service; @Service public class StudentServiceImpl implements StudentService { @PersistenceContext private EntityManager entityManager; @Override @Transactional public void saveAll(List<Student> students) { for (Student student : students) { entityManager.persist(student); } } @Override @Transactional public void deleteAll(List<Student> students) { for (Student student : students) { entityManager.remove(student); } } }