postman đem tiếp lời phản hồi kết quả trừ bỏ có thể 【Sinh thành csv văn kiện】 đến bản địa còn có thể sinh thành json văn kiện. Cụ thể thao tác như sau:
Giống nhau bắt chước tiếp lời phản hồi phê lượng tham số giá trị, thí nghiệm số hiệu như sau:
@Slf4j
@RestController
@RequestMapping("/index")
publicclassIndexController{
@PostMapping("/testGetParams")
privateBizResponse<List<WarehouseDto>>testGetParams(){
List<WarehouseDto>warehouseDtoList=newArrayList<>();
WarehouseDtowarehouseDto1=newWarehouseDto();
warehouseDto1.setId(1L);
warehouseDto1.setDescription("test1");
warehouseDtoList.add(warehouseDto1);
WarehouseDtowarehouseDto2=newWarehouseDto();
warehouseDto2.setId(2L);
warehouseDto2.setDescription("test2");
warehouseDtoList.add(warehouseDto2);
returnResponseUtil.success(warehouseDtoList);
}
}
Cái này tiếp lời phản hồi số liệu kết cấu như sau:
{ "status":1, "code": "10000", "data":[ { "id":1, "description": "test1" }, { "id":2, "description": "test2" } ] }
postman trung tân kiến request, cũng thí nghiệm đem thỉnh cầu phản hồi kết quả sinh thành json văn kiện, bước đi:
1, tăng thêm tiếp lời thỉnh cầu url cùng với thỉnh cầu tham số Body
2, ở Tests trung tăng thêm dưới số hiệu:
vardata=pm.response.json().data;// bắt được cái này số liệu: [ { "id":1, "description": "test1" }, { "id":2, "description": "test2" } ]
console.log(data);
vardataStr='[';
for(vari=0;i<data.length;i++){
dataStr+='{ "id":'+data[i].id+',"description":"' + data[i].description + '"}'+(i==data.length-1?'':',');
}
dataStr+=']';// chỉ lấy ra yêu cầu sinh thành json văn kiện thuộc tính giá trị, lắp ráp số tròn tổ
console.log(dataStr);
let opts={
requestName:request.name||request.url,
fileExtension:'json',// cái này cùng csv văn kiện phối trí không giống nhau
mode:'writeFile',// cái này cùng csv văn kiện phối trí không giống nhau
uniqueIdentifier:false,
responseData:dataStr
};
pm.sendRequest({
url:'http://localhost:3000/write',
method:'POST',
header:'Content-Type:application/json',
body:{
mode:'raw',
raw:JSON.stringify(opts)
}
},function(err,res){
console.log(res);
});
Mặt khác chính là khởi động postman bản địa phục vụ, ( nhưng tham khảo sinh thành csv văn kiện phối trí bản địa phục vụ bước đi ). Thuyên chuyển tiếp lời có thể nhìn đến tiếp lời thuyên chuyển xong sau chấp hành write sinh thành văn kiện, ở hạng mục mục lục hạ C:\soft\ResponseToFile-Postman\Responses hạ có thể nhìn đến sinh thành json văn kiện