目录项目场景:解决方案:补充:Postman测试接口传递对象参数项目场景: postman通常需要传递各式各样的参数,这样的话,进行写参数比较头疼,不知怎么进行传参。 解决方案: 可
postman通常需要传递各式各样的参数,这样的话,进行写参数比较头疼,不知怎么进行传参。
可以考虑将参数对象写成JSON字符串的样式,然后将将字符串转换成json对象
实体类:
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.ibatis.annotations.Param;
import org.hibernate.validator.constraints.Length;
import org.springframework.validation.annotation.Validated;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.Valid;
import javax.validation.constraints.Digits;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "SSM_funds_main")
public class FunsCjyModel implements Serializable {
private static final long serialVersionUID = 1L;
@Id
// @NotNull(message = "id不能为空")
@Length(max = 32,message = "主表id长度不能超过32位")
@Column(name = "BI_RS_ID")
private String biRsId;
@NotNull(message = "所属培训班不能为空")
@Length(max = 32,message = "培训班长度不能超过32位")
@Column(name = "TERM_NAME")
private String termName;
@NotNull(message = "发票购买方不能为空")
@Length(max = 32,message = "发票购买方长度不能超过32位")
@Column(name = "BUYER")
private String buyer;
@NotNull(message = "发票销售方不能为空")
@Length(max = 32,message = "发票销售方长度不能超过32位")
@Column(name = "SALLER")
private String saller;
@Length(max = 32,message = "发票编号长度不能超过32位")
private String billNo;
private Date billDate;
@Digits(integer = 8,fraction = 2,message = "票面金额整数上限为8位,小数点上限为2位")
private BigDecimal billSum;
@Length(max = 100,message = "复印件路径长度不能超过100位")
private String picPath;
@Length(max = 10,message = "文件扩展名称长度不能超过100位")
private String picFileExt;
@Length(max = 32,message = "创建人id长度不能超过32位")
private String createId;
private Date createDate;
@Length(max = 32,message = "修改人id长度不能超过32位")
private String modifyId;
private Date modifyDate;
@Transient
@Valid
private List<DetailCjyModel> list;
}
参数样式:
{
"biRsId":"",
"termName":"实训",
"buyer":"学生",
"saller":"学校",
"billNo":"20210722",
"billSum":"900.00",
"createId":"CJY",
"list":[
{
"rsId":"",
"itemName":"语文",
"itemSpec":"私人",
"itemUnit":"元",
"Qty":"10.00",
"price":"30.00",
"subSum":"300.00",
"taxPercent":"0.1",
"taxAtm":"30.0"
},
{
"rsId":"",
"itemName":"数学",
"itemSpec":"集体",
"itemUnit":"元",
"qty":"20.00",
"price":"30.00",
"subSum":"600.00",
"taxPercent":"0.1",
"taxAtm":"60.0"
}
]
}
控制层代码:
@RequestMapping("/insertFunsDetailTwo")
@ResponseBody
public ResultMap insertFunsDetailTwo(String dataStr,@RequestParam (value = "file",required = false) MultipartFile file){
JSONObject dataStrMap = JSONObject.parseObject(dataStr);
FunsCjyModel funsCjyModel = new FunsCjyModel();
funsCjyModel.setTermName((String)dataStrMap.get("termName"));
funsCjyModel.setBuyer((String)dataStrMap.get("buyer"));
funsCjyModel.setSaller((String)dataStrMap.get("saller"));
funsCjyModel.setBillNo((String)dataStrMap.get("billNo"));
funsCjyModel.setBillSum(funsModelCjyServiceImpl.stringBigeDecimal((String)dataStrMap.get("billSum")));
funsCjyModel.setCreateId((String)dataStrMap.get("createId"));
String list1 = JSON.toJSONString(dataStrMap.get("list"));
List<DetailCjyModel> list = JSONArray.parseArray(list1,DetailCjyModel.class);
funsCjyModel.setList(list);
return funsModelCjyService.insertFunsAndDetail(funsCjyModel,file);
}
这样的话可以用postman的fORM-data传文件和集合对象的参数
url:
使用的是post方式请求
在Headers设置:
在Body写入对象信息,主要红线的地方:
到此这篇关于Postman传递对象参数(包含有集合对象)的文章就介绍到这了,更多相关Postman传递对象参数内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!
--结束END--
本文标题: Postman传递对象参数(包含有集合对象)
本文链接: https://lsjlt.com/news/161895.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
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
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0