需跳转接口
@RestController
@CrossOrigin
@PostMapping("/gotoCarkeeper")
public void gotoCarkeeper(HttpServletResponse response) throws IOException {
Member member = memberMapper.selectByPrimaryKey(UserUtils.getThisMobileUser().getId());
WxMpUserConfig wxUser = wxMpUserMapper.findWxUserByMemberId(member.getMemberId());
JSONObject jsonObject = new JSONObject();
jsonObject.put("member",member);
jsonObject.put("wxUser",wxUser);
doPost(jsonObject);
}
public static JSONObject doPost(JSONObject date) {
HttpClient client = HttpClients.createDefault();
// 要调用的接口方法
String url = "http://localhost:8082/weixin/chichengToLocal";
HttpPost post = new HttpPost(url);
JSONObject jsonObject = null;
try {
StringEntity s = new StringEntity(date.toString());
s.setContentEncoding("UTF-8");
s.setContentType("application/json");
post.setEntity(s);
post.addHeader("content-type", "text/xml");
HttpResponse res = client.execute(post);
/** 以下都是该端口需要做处 理所需要的一些数据 **/
String response1 = EntityUtils.toString(res.getEntity());
System.out.println(response1);
if (res.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
String result = EntityUtils.toString(res.getEntity());// 返回json格式:
jsonObject = JSONObject.parseObject(result);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return jsonObject;
}
跳转接口(接收方)
@CrossOrigin
@RequestMapping("chichengToLocal")
public String chichengToLocal(@RequestBody String content){
JSONObject json = (JSONObject) JSONObject.parse(content);
String member = json.getString("member");
String wxUser = json.getString("wxUser");
return "index";
}
以上就是SpringBoot 不同端口后台跳转(带参)的使用教程,有问题的小伙伴可以评论区或私信提出!
点赞收藏,以留备用!
我是xyushao!我们下期见!
版权声明:本文为weixin_44117178原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。