restful路径参数可以传递5个以内资源对象的操作id,在URI路径上用逗号(,)分割 例如 /assets/1,2,3 [GET, PUT, DELETE] //id为1,2,3的资源

restful路径参数可以传递5个以内资源对象的操作id,在URI路径上用逗号(,)分割

例如 /assets/1,2,3 [GET, PUT, DELETE] //id为1,2,3的资源

RESTful接口规范icon-default.png?t=N7T8https://www.cnblogs.com/lovebing/p/15118553.html以下是例子:

前端vue代码第253~254行:

let ids = that.selectedRowKeys.join(',') // selectedRowKeys=[] 是数组

that.$delete('/cos/stock-put/' + ids).then(() => { ...}); // 以/cos/stock-put/1,2,3,4,5为路径发送删除请求

源码:





后端代码第40~43行:

@DeleteMapping("/{ids}")
// 接收/cos/stock-put/1,2,3,4,5路径参数,自动转换为List列表
public R deleteByIds(@PathVariable("ids") List ids) {
    return R.ok(stockPutService.removeByIds(ids));
}

源码:

package cc.mrbird.febs.cos.controller;


import cc.mrbird.febs.common.utils.R;
import cc.mrbird.febs.cos.entity.StockPut;
import cc.mrbird.febs.cos.service.IStockPutService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author FanK
 */
@RestController
@RequestMapping("/cos/stock-put")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class StockPutController {

    private final IStockPutService stockPutService;

    /**
     * 分页获取入库记录
     * @param page
     * @param stockPut
     * @return
     */
    @GetMapping("/page")
    public R page(Page page, StockPut stockPut) {
        return R.ok(stockPutService.stockPutByPage(page, stockPut));
    }

    /**
     * 删除入库记录
     * @param ids
     * @return
     */
    @DeleteMapping("/{ids}")
    public R deleteByIds(@PathVariable("ids") List ids) {
        return R.ok(stockPutService.removeByIds(ids));
    }

}

你可能感兴趣的:(restful,后端)