當前位置:
首頁 >
4.3. postForObject
發布時間:2025/6/15
31
豆豆
生活随笔
收集整理的這篇文章主要介紹了
4.3. postForObject
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
4.3.1.?傳遞對象
@RequestMapping("/restful/post/{id}")@ResponseBodyprivate static String restfullPost(@PathVariable String id) {final String uri = "http://inf.netkiller.cn/detail/html/{tid}/{cid}/{id}.html";Map<String, String> params = new HashMap<String, String>();params.put("tid", "2");params.put("cid", "2");params.put("id", id);City city = new City("Shenzhen", "Guangdong");RestTemplate restTemplate = new RestTemplate();String result = restTemplate.postForObject(uri, city, String.class, params);return result;}4.3.2.?傳遞數據結構 MultiValueMap
@RequestMapping("/findByMobile")public String findByMobile() {System.out.println("****************************findByMobile******************************");final String uri = "http://www.netkiller.cn/account/getMemberByMobile.json";MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();try {map.add("prefix", "86");map.add("mobile", "13698041116");map.add("_pretty_", "false");} catch (Exception e) {e.printStackTrace();}RestTemplate restTemplate = new RestTemplate();String result = restTemplate.postForObject(uri, map, String.class);System.out.println(map.toString());System.out.println(result);return result;}原文出處:Netkiller 系列 手札
本文作者:陳景峯
轉載請與作者聯系,同時請務必標明文章原始出處和作者信息及本聲明。
總結
以上是生活随笔為你收集整理的4.3. postForObject的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 吐槽: 移动端缓存策略
- 下一篇: https ssl 总结