第一种方式:
List传参,前端将数组数据转为Json字符串,后端再将字符串转为List。
前端:
export function addFinish(data) {
return request({
url: '/task/finish',
method: 'post',
data: JSON.stringify(data)
})
}
后端:
@Log(title = "提交任务", businessType = BusinessType.UPDATE)
@PostMapping
public AjaxResult edit(@RequestBody String taskFinishJsonStr) {
List<TaskFinish> taskFinishList = JSON.parseArray(taskFinishJsonStr, TaskFinish.class);
return toAjax(taskFinishService.saveTaskFinish(taskFinishList));
}
第二种方式:
1.前端VUE js代码:
export function updateListProductCategory(data) {
return request({
url: '/admin/product/category/updateList',
method: 'post',
data: data
})
}
2.调用updateListProductCategory()方法时 对data的处理需要和后端Vo类中的List名称相同
let list= {carrierProductCategoryList:com} //{}中的名称与后端Vo类中的名称相同就可以了
updateListProductCategory(list)
3后端需要封装一个List成Vo类 //lombok提供的@Data注解 会自动给 get/set方法
import lombok.Data;
import java.util.List;
@Data
public class CarrierProductCategoryVo {
private List<CarrierProductCategory> carrierProductCategoryList;
}
4.后端Controller层
@PostMapping("updateList")
public AjaxResult updateList(@RequestBody CarrierProductCategoryVo carrierProductCategoryVo){
return toAjax(carrierProductCategoryService.updateCarrierProductCategoryList(carrierProductCategoryVo.getCarrierProductCategoryList()));
}