4.3. postForObject
生活随笔
收集整理的這篇文章主要介紹了
4.3. postForObject
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
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.?傳遞數(shù)據(jù)結(jié)構(gòu) 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 系列 手札
本文作者:陳景峯
轉(zhuǎn)載請與作者聯(lián)系,同時(shí)請務(wù)必標(biāo)明文章原始出處和作者信息及本聲明。
總結(jié)
以上是生活随笔為你收集整理的4.3. postForObject的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 吐槽: 移动端缓存策略
- 下一篇: https ssl 总结