當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
SpringBoot中使用fastjson将map转换成json
生活随笔
收集整理的這篇文章主要介紹了
SpringBoot中使用fastjson将map转换成json
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
場景
請求參數需要傳遞如下類型的參數
{"TableName":"wms_receive_order","PrintID":["28"]}實現
打開項目的pom.xml
<dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.24</version></dependency>添加如下依賴并下載依賴包
來到后臺Controller
導入jar包
import com.alibaba.fastjson.JSON;使用
?String? param= JSON.toJSONString(map);舉例
@ResponseBody@RequestMapping(value = "/doPrintPostRequest")public Map<String, Object> doPrintPostRequest(@RequestBody Map<String, Object> params) {Map<String, Object> result = new HashMap<String, Object>();Object PrintId = params.get("id");String paramID="";if(PrintId!=null){paramID=PrintId.toString();}String URL="";Map map=new HashMap();map.put("TableName","wms_receive_order");List<Object> idList=new ArrayList<Object>();idList.add(paramID);map.put("PrintID",idList);String? param= JSON.toJSONString(map);String message = HttpRequestUtil.sendPost(URL, param);result.put("statusCode",? "200");result.put("message", message);return result;}?
總結
以上是生活随笔為你收集整理的SpringBoot中使用fastjson将map转换成json的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SpringBoot中使用thymele
- 下一篇: SpringBoot中使用类型安全的配置