SpringBoot 不同端口后台跳转(带参)

it2025-09-16  1

需跳转接口

@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"; }
最新回复(0)