public boolean deleteByIds(List<Integer> ids) { List<BisTask> tasks = new ArrayList<>(); for (Integer id : ids) { BisTask task = new BisTask(); task.setId(id); task.setIsDel(1); tasks.add(task); } return this.updateBatchById(tasks); },用DataResult在congtroller写个调用方法
时间: 2024-01-01 08:03:27 浏览: 144
好的,你可以参考以下代码实现:
```java
@RestController
@RequestMapping("/task")
public class TaskController {
@Autowired
private BisTaskService bisTaskService;
@PostMapping("/deleteByIds")
public DataResult<Boolean> deleteByIds(@RequestBody List<Integer> ids) {
boolean success = bisTaskService.deleteByIds(ids);
if (success) {
return DataResult.success(true);
} else {
return DataResult.fail("删除任务失败");
}
}
}
```
在上述代码中,我们注入了 `BisTaskService`,并在 `deleteByIds` 方法中调用了 `BisTaskService` 的 `deleteByIds` 方法。根据 `deleteByIds` 方法的返回值,我们构建了不同的 `DataResult` 对象进行返回。如果删除成功,则返回 `DataResult.success(true)`,否则返回 `DataResult.fail("删除任务失败")`。
需要注意的是,由于我们使用了 `@RequestBody` 注解,因此在请求时需要将参数转换为 JSON 格式进行传递。你可以使用 Postman 或其他工具进行测试。
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![java](https://img-home.csdnimg.cn/images/20250102104920.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)