Java两个项目之间的对接接口


可以用httpclient来进行连接,但是spring都封装在RestTemplate中了,所以直接调用就可以

接口1:

@Autowired
RestTemplate restTemplate;

    @RequestMapping(value = "/interface1", method = RequestMethod.POST)
    public JSONArray merchantDetail() throws IOException {
        JSONObject jsonObject = null;
        List map = restTemplate.postForObject("http://localhost:7070/demo/interface2", jsonObject, List.class);
        JSONArray jsonObject1 = new JSONArray(map);
        ReturnValue rv = ReturnValue.success();
        rv.setData(jsonObject1);
        return jsonObject1;
    }

接口2:

@RequestMapping(value = "/demo/interface2", method = RequestMethod.POST)
    public List interface2() throws IOException {
        List<Demo> demoList = new ArrayList<>();
        Map map = new HashMap();
        List list = new ArrayList();
        for (int i=0; i<3; i++){
            Demo demo = new Demo();
            demo.setId("000"+i);
            demo.setCode("4568971");
            list.add(demo);
        }
        return list;
    }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM