1.在使用postForObject发送请求的时候 如果需要传递参数
请大家使用
// 封装参数,千万不要替换为Map与HashMap,否则参数无法传递
MultiValueMap<String, String> paramMap = new LinkedMultiValueMap<String, String>();
客户端
String url = "http://localhost:8080/customerVisitController/test.do";
FilterCondition fc = new FilterCondition();
fc.setUserId("111");
fc.setPageNo(22);
MultiValueMap<String, Object> map = new LinkedMultiValueMap<String,Object>();
map.add("key",new Gson().toJson(fc));
String s = new RestTemplate().postForObject(url, map, String.class);
服务端
@RequestMapping(value = "/test")
@ResponseBody
public Response test(HttpServletRequest request){
System.out.println(request.getParameter("key"));
String key = request.getParameter("key");
FilterCondition filterCondition = new Gson().fromJson(key, FilterCondition.class);
return new Response().success("aaa");
}