TestBatchController.java 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package com.ruoyi.demo.controller;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.ruoyi.common.core.controller.BaseController;
  4. import com.ruoyi.common.core.domain.AjaxResult;
  5. import com.ruoyi.demo.domain.TestDemo;
  6. import com.ruoyi.demo.service.ITestDemoService;
  7. import lombok.RequiredArgsConstructor;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.web.bind.annotation.DeleteMapping;
  10. import org.springframework.web.bind.annotation.PostMapping;
  11. import org.springframework.web.bind.annotation.RequestMapping;
  12. import org.springframework.web.bind.annotation.RestController;
  13. import java.util.ArrayList;
  14. import java.util.List;
  15. /**
  16. * 测试批量方法
  17. *
  18. * @author Lion Li
  19. * @date 2021-05-30
  20. */
  21. @RequiredArgsConstructor(onConstructor_ = @Autowired)
  22. @RestController
  23. @RequestMapping("/demo/batch")
  24. public class TestBatchController extends BaseController {
  25. private final ITestDemoService iTestDemoService;
  26. /**
  27. * 新增批量方法
  28. */
  29. @PostMapping()
  30. public AjaxResult<Void> add() {
  31. List<TestDemo> list = new ArrayList<>();
  32. for (int i = 0; i < 1000; i++) {
  33. list.add(new TestDemo().setOrderNum(-1L).setTestKey("批量新增").setValue("测试新增"));
  34. }
  35. return toAjax(iTestDemoService.saveAll(list) ? 1 : 0);
  36. }
  37. /**
  38. * 修改批量方法
  39. */
  40. @DeleteMapping()
  41. public AjaxResult<Void> edit() {
  42. return toAjax(iTestDemoService.remove(new LambdaQueryWrapper<TestDemo>()
  43. .eq(TestDemo::getOrderNum, -1L)) ? 1 : 0);
  44. }
  45. }