本文小编为大家详细介绍“如何调用postman的函数格式化”,内容详细,步骤清晰,细节处理妥当,希望这篇“如何调用postman的函数格式化”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。
方法一:升级版本格式化
1、升级到version 6.7.4版本
2、点击Beautify即可格式化Body里面的JSON
方法二:调用postman的函数格式化
package com.java.example.demo.postman;
import com.alibaba.fastjson.JSONObject;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;
/**
* postman中常量及函数的使用
*
* 场景:
* secondFunction这个方法需要依赖 firstFunction方法 执行的结果
* 使用一个postman请求解决
*/
@RestController
public class Constant {
@GetMapping("/first")
@ResponseBody
public ResponseEntity<String> firstFunction(@RequestParam String param){
return res(param + "-init");
}
@GetMapping("/second")
@ResponseBody
public ResponseEntity<String> secondFunction(@RequestParam String param){
return res("加工后的随机数:" + param);
}
private static ResponseEntity<String> res(Object object){
Map<String,Object> map = new HashMap<>();
map.put("res",object);
return jsonResult(JSONObject.toJSONString(map));
}
public static ResponseEntity jsonResult(String result) {
HttpHeaders resHeaders = new HttpHeaders();
resHeaders.set("Content-Type", "application/json;charset=UTF-8");
return new ResponseEntity(result, resHeaders, HttpStatus.OK);
}
}
读到这里,这篇“如何调用postman的函数格式化”文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注亿速云行业资讯频道。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
原文链接:https://my.oschina.net/u/4592498/blog/4473035