怎么进行Hessian入门
这篇文章给大家介绍怎么进行Hessian入门,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
专注于为中小企业提供网站制作、网站建设服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业罗定免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了数千家企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。
创建一个web项目hessianServer,导入 hessian-4.0.62.jar
创建 Customer 实现 Serializable 接口
import java.io.Serializable; public class Customer implements Serializable { private String id; private String name; private String address; ... }
创建 CustomerServiceImpl
package com.gwl.crm.service.impl; import com.gwl.crm.model.Customer; import com.gwl.crm.service.CustomerService; import java.util.ArrayList; import java.util.List; public class CustomerServiceImpl implements CustomerService { @Override public ListfindAll() { Customer c1 = new Customer("01","zhangsan","beijing"); Customer c2 = new Customer("02","lisi","shenzhen"); List customers = new ArrayList<>(); customers.add(c1); customers.add(c2); return customers; } }
配置 web.xml
hessian com.caucho.hessian.server.HessianServlet home-class com.gwl.crm.service.impl.CustomerServiceImpl home-api com.gwl.crm.service.CustomerService hessian /hessian/customer
创建一个客户端项目,导入 hessian-4.0.62.jar,复制web项目hessianServer 中的 Customer 和 CustomerService到客户端项目中
import com.caucho.hessian.client.HessianProxyFactory; import java.util.List; public class Main { public static void main(String[] args) throws Exception { HessianProxyFactory factory = new HessianProxyFactory(); CustomerService customerService = (CustomerService) factory.create(CustomerService.class,"http://localhost:8080/hessianServer_war_exploded/hessian/customer"); Listcustomers = customerService.findAll(); // 输出 [{address=beijing, name=zhangsan, id=01}, {address=shenzhen, name=lisi, id=02}] System.out.println(customers); } }
关于怎么进行Hessian入门就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
文章题目:怎么进行Hessian入门
URL网址:http://ybzwz.com/article/psejjh.html