Postmain集成spring测试:
postmain传递json格式字符串的数组格式,后端接收的样列:
1.postmain要测试需要登录的网站必须协带对应登录后获取的cookie或者token令牌放到请求头中
系统登录后的cookie头:
图片.png
携带cookie头到postmian中:
图片.png
2.编写后端访问路径,写好接口,这里演示俩种接收方式:
- 第一种是安map接收,所有的数据都封装到map中
- 第二种直接用request.getParameter(data);方式接收
@RequestMapping("/text")
@ResponseBody
public void aliReceive(@RequestParam Map<String, String> paramsMap) {
System.out.println(paramsMap.toString());
//这个是生成表格中填写的所有数据
String data1 = request.getParameter("data");
//将数据转换成字符入库表的实体类型 转成parseArray数组形式返回一个集合
List<GovPutInfoMVO> govPutInfoMVOS = com.alibaba.fastjson.JSONObject.parseArray(data1, GovPutInfoMVO.class);
System.out.println(data1);
System.out.println(govPutInfoMVOS);
}
3.前端json示例:
{"EW_ID":"1",
"SE_ID":"1",
"monthly":"2021-07",
"putDate":"2021-02-11",
"seErpNumber":"8787",
"stuts":"",
"telephone":"13445556666",
"warehousePeople":"99999",
"data":[{"breed":"N95医用级防护口罩",
"unit":"只",
"breedCode":"XFPYLFHWZ002",
"specifications":"24225442542",
"batchNumber":"1",
"price":"1",
"inventoryQuantity":"2",
"contractNumber":"2",
"isAbilityEnterprise":"1",
"manufacturerName":"34",
"isProvinceEnterprises":"1",
"effectiveDate":"2021-02-19",
"subordinateProvince":"430000",
"index":1
},{
"breed":"N95医用级防护口罩",
"unit":"只",
"breedCode":"XFPYLFHWZ002",
"specifications":"24225442542",
"batchNumber":"1",
"price":"1",
"inventoryQuantity":"2",
"contractNumber":"2",
"isAbilityEnterprise":"1",
"manufacturerName":"34",
"isProvinceEnterprises":"1",
"effectiveDate":"2021-02-19",
"subordinateProvince":"430000",
"index":2}]}
4.Postmain传递参数示例
图片.png
网友评论