当前位置: 首页 > news >正文

jpa批量删除 deleteInBatch方式

jpa批量删除可以调用JpaRepository的deleteInBatch(Iterable<T> entities)方法,同时把实体列表传参给这个方法。


Service

StudentServiceImpl.java

@Service("studentServiceImpl")
public class StudentServiceImpl implements StudentService {

	@Autowired
	private StudentRepository studentRepository;

	@Transactional
	public List<Student> saveAllStudent(List<Student> studentList) {
		List<Student> response = (List<Student>) studentRepository.saveAll(studentList);
		return response;
	}

	@Transactional
	public void deleteInBatch(List<Student> studentList) {
		studentRepository.deleteInBatch(studentList);
	}

}

Repository

在service层调用studentRepository的deleteInBatch方法,StudentRepository之所以有这个方法,是因为它继承了JpaRepository

StudentRepository.java – interface

@Repository
public interface StudentRepository extends JpaRepository<Student, Serializable> {

}

Controller

最后去controller调用service的方法

StudentController.java

@RestController
@RequestMapping(value = "/student")
public class StudentController {

	@Autowired
	private StudentService studentService;

	@RequestMapping(value = "/deleteinbatch", method = RequestMethod.DELETE)
	@ResponseBody
	public String deleteInBatch(@RequestBody List<Student> studentList) {
		studentService.deleteInBatch(studentList);
		return "All Students deleted successfully";
	}

}

相关文章:

  • jpa在对主表更新的同时对关联表进行更新操作
  • type: Object, default: 数组/对象的写法
  • 腾讯文档的表格设置行高
  • java order by 防止注入的方法
  • required a bean of type that could not be found. The injection point has the following annotations:
  • 删除换行符在线 在线删除所有回车换行工具
  • 实现将HashMap转换成为ArrayList,并将map的Key 、Value分别存放到两个ArrayList当中
  • java switch可以字符串吗
  • @Query中countQuery的介绍
  • java8 Stream将List转成Map
  • ORDER BY clause is not in GROUP BY clause and contains nonaggregated column ‘xxx.sxxx_.id‘ which is
  • group by 和 where一起使用
  • java求多个Long的平均数,其中可能有null
  • java遍历Map的四种方法
  • win11窗口分1/3 2/3屏的方法
  • 03Go 类型总结
  • C# 免费离线人脸识别 2.0 Demo
  • CentOS6 编译安装 redis-3.2.3
  • Electron入门介绍
  • JavaScript 事件——“事件类型”中“HTML5事件”的注意要点
  • js中forEach回调同异步问题
  • PHP 的 SAPI 是个什么东西
  • php面试题 汇集2
  • Redis字符串类型内部编码剖析
  • 来,膜拜下android roadmap,强大的执行力
  • 两列自适应布局方案整理
  • 前嗅ForeSpider中数据浏览界面介绍
  • 山寨一个 Promise
  • 一个JAVA程序员成长之路分享
  • 因为阿里,他们成了“杭漂”
  • 优化 Vue 项目编译文件大小
  • 智能网联汽车信息安全
  • 小白应该如何快速入门阿里云服务器,新手使用ECS的方法 ...
  • #Linux(Source Insight安装及工程建立)
  • (pojstep1.1.1)poj 1298(直叙式模拟)
  • (Repost) Getting Genode with TrustZone on the i.MX
  • (Ruby)Ubuntu12.04安装Rails环境
  • (二)springcloud实战之config配置中心
  • (附源码)springboot社区居家养老互助服务管理平台 毕业设计 062027
  • (附源码)ssm捐赠救助系统 毕业设计 060945
  • (力扣记录)1448. 统计二叉树中好节点的数目
  • (亲测)设​置​m​y​e​c​l​i​p​s​e​打​开​默​认​工​作​空​间...
  • (转)EXC_BREAKPOINT僵尸错误
  • (转载)hibernate缓存
  • (转载)跟我一起学习VIM - The Life Changing Editor
  • **PHP二维数组遍历时同时赋值
  • .bat批处理(五):遍历指定目录下资源文件并更新
  • .md即markdown文件的基本常用编写语法
  • .NET CORE 第一节 创建基本的 asp.net core
  • .net core 客户端缓存、服务器端响应缓存、服务器内存缓存
  • .net core 源码_ASP.NET Core之Identity源码学习
  • .NET Framework 的 bug?try-catch-when 中如果 when 语句抛出异常,程序将彻底崩溃
  • .NET 程序如何获取图片的宽高(框架自带多种方法的不同性能)
  • @column注解_MyBatis注解开发 -MyBatis(15)
  • @property括号内属性讲解