Python 官方文档:入门教程 => 点击学习
目录postman传参的几种格式1.参数中有基本数据类型还有 list集合类型2. 参数中有基本数据类型,还有 Map<Long,List<Long>>这种类
百度了好久,还是自己摸索出来的。。。
public String addUserRole(@RequestParam("userId")Long userId,
@RequestBody List<Long> roleIdList)
addRolePermission(@RequestParam("roleId") Long roleId,
@RequestBody Map<Long, List<Long>> metaMap)
object包含一个spuId,一个skuList
就普通的参数传递即可。
@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页面的请求可以这么写:
@RequestMapping("deleteCustomerByIds")
public Boolean deleteCustomerByIds(@RequestParam("ids[]") List<String> ids){
Boolean result = mongoService.deleteCustomer(ids);
return result;
}
@RequestMapping("deleteCustomerByCustomers")
public Boolean deleteCustomerByCustomers(@RequestBody List<Customer> customers){
List<String> ids = new ArrayList<>();
ids.add("1234");
Boolean result = mongoService.deleteCustomer(ids);
return result;
}
实体类中引用了一个List,泛型为其他实体类
参数是List集合时,Postman中参数格式如下图所示:
如需要传入一个String,一个List<String>
输入参数后报错:@RequestBody对象为空,异常Required request body is missing
直接拦截了入参为空的请求,设置@RequestBody(required = false)后,将不会拦截,可以在后端进行判断
原因是两个参数都使用了@RequestBody接收,正确做法应该是分别使用@RequestParam("id"),@RequestParam("list")指定参数
在Body中选择x-www-fORM-urlencoded的方式,将map中所需的key和value值输入即可
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。
--结束END--
本文标题: 关于postman传参的几种格式 list,map 等
本文链接: https://www.lsjlt.com/news/133753.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0