這篇文章給大家介紹怎么進(jìn)行Hessian入門(mén),內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。
專注于為中小企業(yè)提供網(wǎng)站制作、網(wǎng)站建設(shè)服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)羅定免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了數(shù)千家企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過(guò)網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
創(chuàng)建一個(gè)web項(xiàng)目hessianServer,導(dǎo)入 hessian-4.0.62.jar
創(chuàng)建 Customer 實(shí)現(xiàn) Serializable 接口
import java.io.Serializable; public class Customer implements Serializable { private String id; private String name; private String address; ... }
創(chuàng)建 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
創(chuàng)建一個(gè)客戶端項(xiàng)目,導(dǎo)入 hessian-4.0.62.jar,復(fù)制web項(xiàng)目hessianServer 中的 Customer 和 CustomerService到客戶端項(xiàng)目中
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); } }
關(guān)于怎么進(jìn)行Hessian入門(mén)就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。