java实现跨系统接口调用简单
来源:互联网 发布:淘宝上比较好的手办店 编辑:程序博客网 时间:2024/06/13 16:12
以spring mvc框架为例 抛开权限,认证限制 controller代码
package com.it.portal.controller.api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.it.portal.controller.BaseController;
import com.it.portal.service.SystemService;
/**
* @author zhangqg
* @date 2017年11月8日
* 类说明
*/
@Controller
@RequestMapping("/api")
public class EbayUserApiController extends BaseController {
@Autowired
private SystemService systemService;
@RequestMapping(value = "/ebayUser/getAllEbayUser", method = RequestMethod.POST)
@ResponseBody
public Object getEbayUserList()
{
return systemService.getEbayUserList();
}
}
接口调用代码
CommonsProperty commonsProperty=(CommonsProperty)SpringUtils.getBean("commonsProperty");
HttpPost httpRequst = new HttpPost(commonsProperty.getUriAPI());// 创建HttpPost对象
httpRequst.addHeader("Content-type","application/json; charset=utf-8");
httpRequst.addHeader("Accept", "application/json");
List<EbayUser> users = null;
try {
HttpResponse httpResponse = HttpClients.createDefault().execute(httpRequst);
if (httpResponse.getStatusLine().getStatusCode() == 200) {
HttpEntity httpEntity = httpResponse.getEntity();
String result = EntityUtils.toString(httpEntity);// 取出应答字符串
JSONArray json = JSONArray.fromObject(result);// userStr是json字符串
users = (List<EbayUser>) JSONArray.toCollection(json, EbayUser.class);
}
} catch (Exception e) {
e.printStackTrace();
}
- java实现跨系统接口调用简单
- java调用WEBSERVICE接口简单实现
- java 实现WebService接口调用
- dubbo+zookeeper 简单实现远程接口调用
- java简单实现webservice接口
- Java 简单的接口实现
- java简单实现webservice接口
- java简单实现webservice接口
- java简单实现webservice接口
- android 调用java编写接口 简单示例
- http接口的调用于被调用的简单实现
- 5.系统接口——系统调用的实现
- java天气预报调用百度接口实现
- JAVA RMI实现远程接口调用
- Apache HttpClient 实现 Java 调用 Http 接口
- WebService入门java实现服务端接口调用
- java实现客户端Client调用Restful接口
- Java实现Web Api接口远程调用
- Android mkdir与mkdirs均失效解决方案
- maven编译scala,依赖包打包到jar里
- 695. Max Area of Island
- (17)QBC、QBE
- git 简单使用笔记
- java实现跨系统接口调用简单
- docker error Couldn't connect to Docker daemon at http+docker://localunixsocket
- OKHTTP拦截器工作过程
- NYOJ 72
- 原生js插件开发入门
- PAT
- [近期学习心得]CCNA+django
- linux cut命令用法
- Spring框架使用纯注解的方式来配置IOC