Vue+SpringBoot List passing parameters

First way:

List parameters are passed, the front end converts the array data into a Json string, and the back end converts the string into a List.

front end:

export function addFinish(data) {
  return request({
    url: '/task/finish',
    method: 'post',
    data: JSON.stringify(data)
  })
}

rear end:

    @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));

    }

Second way:

1. Front-end VUE js code:

export function updateListProductCategory(data) {
    return request({
        url: '/admin/product/category/updateList',
        method: 'post',
        data: data
    })
}


2. When calling the updateListProductCategory() method, the data processed needs to be the same as the List name in the backend Vo class.

let list= {carrierProductCategoryList:com}  //{}中的名称与后端Vo类中的名称相同就可以了
updateListProductCategory(list)


3 The backend needs to encapsulate a List into the Vo class //The @Data annotation provided by lombok will automatically give the get/set method

import lombok.Data;
import java.util.List;
@Data
public class CarrierProductCategoryVo {
    private List<CarrierProductCategory> carrierProductCategoryList;
}


4. Backend Controller layer

@PostMapping("updateList")
public AjaxResult updateList(@RequestBody CarrierProductCategoryVo carrierProductCategoryVo){
        return toAjax(carrierProductCategoryService.updateCarrierProductCategoryList(carrierProductCategoryVo.getCarrierProductCategoryList()));
}

Guess you like

Origin blog.csdn.net/heni6560/article/details/125951400