1.在使用postForObject发送请求的时候 如果需要传递参数
请大家使用
// 封装参数,千万不要替换为Map与HashMap,否则参数无法传递
MultiValueMap<String, String> paramMap = new LinkedMultiValueMap<String, String>();
客户端
String url = "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")@ResponseBodypublic Response test(HttpServletRequest request){System.out.Parameter("key"));String key = Parameter("key");FilterCondition filterCondition = new Gson().fromJson(key, FilterCondition.class);return new Response().success("aaa");}
本文发布于:2024-02-03 08:55:28,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170692172849975.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |