温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

postman传参的格式有哪些

发布时间:2021-08-27 11:15:01 来源:亿速云 阅读:1071 作者:小新 栏目:开发技术

这篇文章主要介绍了postman传参的格式有哪些,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

postman传参的几种格式

1.参数中有基本数据类型还有 list集合类型

   public String addUserRole(@RequestParam("userId")Long userId,
                              @RequestBody List<Long> roleIdList)

postman传参的格式有哪些

2. 参数中有基本数据类型,还有 Map<Long,List<Long>>这种类型

addRolePermission(@RequestParam("roleId") Long roleId,
                  @RequestBody Map<Long, List<Long>> metaMap)

postman传参的格式有哪些

PostMan请求Object\List、Map类型

Object参数传递

object包含一个spuId,一个skuList

postman传参的格式有哪些

List参数传递

一、简单的参数参数传递 Controller

就普通的参数传递即可。

/**
     * 删除Customer
     * 根据ID删除
     * @return
     */
    @RequestMapping("deleteCustomerById")
    public Boolean deleteCustomerById(String id){
 
        Boolean result = mongoService.deleteCustomer(id);
 
        return result;
    }

前后台分离项目,使用Postman对写好的接口进行测试,请求类型为Post需要向后台传递List<String> list数据下面是后台控制层的java代码

@RequestMapping(value = "/del",method = RequestMethod.POST,produces = "application/json")
public Result del(@RequestBody List<String> list)

Postman页面的请求可以这么写:

postman传参的格式有哪些

二、List和数组,组成形如List<String>等基本数据类型传参
/**
     * 批量删除
     * @param ids
     * @return
     */
    @RequestMapping("deleteCustomerByIds")
    public Boolean deleteCustomerByIds(@RequestParam("ids[]") List<String> ids){
 
        Boolean result = mongoService.deleteCustomer(ids);
 
        return result;
    }

postman传参的格式有哪些

三、复杂List<Object>请求操作
/**
     * 批量删除
     * @param customers
     * @return
     */
    @RequestMapping("deleteCustomerByCustomers")
    public Boolean deleteCustomerByCustomers(@RequestBody List<Customer> customers){
 
        List<String> ids = new ArrayList<>();
        ids.add("1234");
        Boolean result = mongoService.deleteCustomer(ids);
 
        return result;
    }

postman传参的格式有哪些

实体类中引用了一个List,泛型为其他实体类

postman传参的格式有哪些

参数是List集合时,Postman中参数格式如下图所示:

postman传参的格式有哪些

Postman传入多个参数,请求异常Required request body is missing

如需要传入一个String,一个List<String>

输入参数后报错:@RequestBody对象为空,异常Required request body is missing

直接拦截了入参为空的请求,设置@RequestBody(required = false)后,将不会拦截,可以在后端进行判断

原因是两个参数都使用了@RequestBody接收,正确做法应该是分别使用@RequestParam("id"),@RequestParam("list")指定参数

postman传参的格式有哪些

Map类型

Map<String,String>

在Body中选择x-www-form-urlencoded的方式,将map中所需的key和value值输入即可

Map< String, List<String> >

postman传参的格式有哪些

感谢你能够认真阅读完这篇文章,希望小编分享的“postman传参的格式有哪些”这篇文章对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,更多相关知识等着你来学习!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI