Vue+SpringBoot パラメータを渡すリスト

最初の方法:

リスト パラメーターが渡され、フロント エンドで配列データが Json 文字列に変換され、バック エンドで文字列がリストに変換されます。

フロントエンド:

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

    }

2番目の方法:

1. フロントエンド VUE js コード:

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


2. updateListProductCategory() メソッドを呼び出す場合、処理されるデータはバックエンド Vo クラスのリスト名と同じである必要があります。

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


3 バックエンドはリストを Vo クラスにカプセル化する必要があります // lombok によって提供される @Data アノテーションは自動的に get/set メソッドを提供します

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


4. バックエンドコントローラー層

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

おすすめ

転載: blog.csdn.net/heni6560/article/details/125951400