【springboot+mybatisplus】批量增加

第一种方法:使用mybatis的Service CRUD接口 saveBatch()saveBatch/** * 插入(批量) * * @param entityList 实体对象集合 * @param batchSize 插入批次数量 */boolean saveBatch(Collection<T> entityList);#saveBatch/** *...
摘要由CSDN通过智能技术生成

第一种方法:使用mybatis的Service CRUD接口 saveBatch()

saveBatch
/**
 * 插入(批量)
 *
 * @param entityList 实体对象集合
 * @param batchSize  插入批次数量
 */
boolean saveBatch(Collection<T> entityList);


#saveBatch
/**
 * 插入(批量)
 * 
 * @param entityList 实体对象集合
 * @param batchSize  插入批次数量
 */
boolean saveBatch(Collection<T> entityList, int batchSize);

实现层代码:

@Override
    public Result roleRelationRoot(int roleId, List<Integer> rootIds) {
   

        List list = new ArrayList();
        for(int i=0;i<rootIds.size(
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现批量删除,可以按照以下步骤进行: 1. 前端页面中,勾选需要删除的数据,点击“删除”按钮,将所选数据的id封装成一个数组,通过axios发送到后端。 2. 后端接收前端传来的id数组,根据id数组中的id,从数据库中删除对应数据。 3. 在SpringBoot中,可以使用@DeleteMapping注解来接收前端发送的DELETE请求,并在方法体中实现删除操作。在MyBatisPlus中,可以使用wrapper进行批量删除操作。 4. 最后,后端返回删除结果给前端。 下面是一个简单的代码示例: 前端代码: ``` <template> <div> <el-table :data="tableData" style="width: 100%"> <el-table-column type="selection"></el-table-column> <el-table-column prop="name" label="姓名"></el-table-column> <el-table-column prop="age" label="年龄"></el-table-column> <el-table-column prop="gender" label="性别"></el-table-column> <el-table-column fixed="right" label="操作"> <template slot-scope="scope"> <el-button type="danger" size="mini" @click="handleDelete(scope.row.id)">删除</el-button> </template> </el-table-column> </el-table> <el-button type="danger" @click="batchDelete">批量删除</el-button> </div> </template> <script> import axios from 'axios'; export default { data() { return { tableData: [], // 表格数据 multipleSelection: [], // 多选数组 }; }, methods: { // 删除单条数据 handleDelete(id) { axios.delete('/api/delete/' + id).then((res) => { this.getTableData(); }); }, // 批量删除 batchDelete() { const ids = this.multipleSelection.map((item) => item.id); axios.delete('/api/batchDelete', { data: ids, }).then((res) => { this.getTableData(); this.multipleSelection = []; }); }, // 获取表格数据 getTableData() { axios.get('/api/getTableData').then((res) => { this.tableData = res.data; }); }, }, created() { this.getTableData(); }, }; </script> ``` 后端代码: ``` @RestController @RequestMapping("/api") public class UserController { @Autowired private UserService userService; // 删除单条数据 @DeleteMapping("/delete/{id}") public boolean delete(@PathVariable("id") Long id) { return userService.removeById(id); } // 批量删除 @DeleteMapping("/batchDelete") public boolean batchDelete(@RequestBody List<Long> ids) { return userService.removeByIds(ids); } } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值