标签:
1、spring xml 配置
<!-- JSON转换器 --> <bean id="jsonConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>text/html;charset=UTF-8</value> <value>application/json; charset=UTF-8</value> </list> </property> </bean> <!-- Client --> <bean id="restTemplate" class="org.springframework.web.client.RestTemplate"> <property name="messageConverters"> <list> <ref bean="jsonConverter" /> </list> </property> </bean>
@Autowired RestTemplate restTemplate; public static final String syncChatUrl = "/rest/mucroom/sync?type={type}&doorPass={doorPass}"; @SuppressWarnings({ "unchecked", "rawtypes" }) public Map<String, Object> syncChat(int type) { try { Map<String, Object> resultMap = new HashMap<String, Object>(); HashMap<String, String> uriVariables = new HashMap<String, String>(); uriVariables.put("type", type + ""); uriVariables.put("doorPass", "dafjdasklfjasklfjkasl"); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity<String> requestEntity = new HttpEntity<String>(headers); ResponseEntity<Map> body = restTemplate.exchange(iflahbuChatUrl + TimerConstant.syncChatUrl, HttpMethod.GET, requestEntity, Map.class,uriVariables); resultMap = body.getBody(); return resultMap; } catch (Exception e) { logger.error("sync chat error:" + e); }
标签:
原文地址:http://my.oschina.net/fengshuzi/blog/497380