千家信息网

如何调用postman的函数格式化

发表于:2024-09-22 作者:千家信息网编辑
千家信息网最后更新 2024年09月22日,本文小编为大家详细介绍"如何调用postman的函数格式化",内容详细,步骤清晰,细节处理妥当,希望这篇"如何调用postman的函数格式化"文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来
千家信息网最后更新 2024年09月22日如何调用postman的函数格式化

本文小编为大家详细介绍"如何调用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请求解决 */@RestControllerpublic class Constant {    @GetMapping("/first")    @ResponseBody    public ResponseEntity firstFunction(@RequestParam String param){return res(param + "-init");}    @GetMapping("/second")    @ResponseBody    public ResponseEntity secondFunction(@RequestParam String param){return res("加工后的随机数:" + param);}    private static ResponseEntity res(Object object){        Map 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的函数格式化"文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注行业资讯频道。

0