一. 在服务端发布一个web项目

1.创建一个动态的web项目,并导入hessian的jar包

2. 在服务端的crm项目中创建接口

package cn.rodge.crm.service;
import java.util.List;
import cn.rodge.crm.domain.Customer;
// 客户服务接口
public interface CustomerService {
    // 未关联定区客户
    public List<Customer> findnoassociationCustomers();
    // 查询已经关联指定定区的客户
    public List<Customer> findhasassociationCustomers(String decidedZoneId);
    // 将未关联定区客户关联到定区上
    public void assignCustomersToDecidedZone(Integer[] customerIds, String decidedZoneId); 
    // 根据电话查询客户
    public List<Customer> findCustomerByTelephone (String telephone);  
    //根据地址查询定区id
    public String findDecidedZoneByAddress (String address);
}

Customer.java实体类
package cn.rodge.crm.domain;
import java.io.Serializable;
public class Customer implements Serializable {
    private Integer id;
    private String name;
    private String station;
    private String telephone;
    private String address;
    private String decidedzone_id;
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getStation() {
        return station;
    }
    public void setStation(String station) {
        this.station = station;
    }
    public String getTelephone() {
        return telephone;
    }
    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }
    public String getAddress() {
        return address;
    }
    public void setAddress(String address) {
        this.address = address;
    }
    public String getDecidedzone_id() {
        return decidedzone_id;
    }
    public void setDecidedzone_id(String decidedzone_id) {
        this.decidedzone_id = decidedzone_id;
    }
}

Customer.hbm.xml映射文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="cn.rodge.crm.domain.Customer" table="t_customer">
        <id name="id">
            <generator class="native"></generator>
        </id>
        <property name="name"></property>
        <property name="station"></property>
        <property name="telephone"></property>
        <property name="address"></property>
        <property name="decidedzone_id"></property>
    </class>
</hibernate-mapping>

3.针对接口提供实现类

package cn.rodge.crm.service.impl;
import java.util.List;
import org.hibernate.Session;
import cn.rodge.crm.domain.Customer;
import cn.rodge.crm.service.CustomerService;
import cn.rodge.crm.utils.HibernateUtils;
public class CustomerServiceImpl implements CustomerService {
    public List<Customer> findnoassociationCustomers() {
        Session session = HibernateUtils.openSession();
        session.beginTransaction();
        String hql = "from Customer where decidedzone_id is null";
        List<Customer> customers = session.createQuery(hql).list();
        session.getTransaction().commit();
        session.close();
        return customers;
    }
    public List<Customer> findhasassociationCustomers(String decidedZoneId) {
        Session session = HibernateUtils.openSession();
        session.beginTransaction();
        String hql = "from Customer where decidedzone_id = ?";
        List<Customer> customers = session.createQuery(hql).setParameter(0, decidedZoneId).list();
        session.getTransaction().commit();
        session.close();
        return customers;
    }
    public void assignCustomersToDecidedZone(Integer[] customerIds, String decidedZoneId) {
        Session session = HibernateUtils.openSession();
        session.beginTransaction();
        // 取消定区所有关联客户
        String hql2 = "update Customer set decidedzone_id=null where decidedzone_id=?";
        session.createQuery(hql2).setParameter(0, decidedZoneId).executeUpdate();
        // 进行关联
        String hql = "update Customer set decidedzone_id=? where id =?";
        if (customerIds != null) {
            for (Integer id : customerIds) {
                session.createQuery(hql).setParameter(0, decidedZoneId).setParameter(1, id).executeUpdate();
            }
        }
        session.getTransaction().commit();
        session.close();
    }
    public List<Customer> findCustomerByTelephone(String telephone) {
        Session session = HibernateUtils.openSession();
        session.beginTransaction();
        String hql = "from Customer  where telephone = ?";
        List<Customer> customers = session.createQuery(hql).setParameter(0, telephone).list();
        session.getTransaction().commit();
        session.close();
        return customers;
    }
    public String findDecidedZoneByAddress(String address) {
        Session session = HibernateUtils.openSession();
        session.beginTransaction();
        String hql = "select decidedzone_id from Customer  where address = ?";
        List<String> list = session.createQuery(hql).setParameter(0, address).list();
        String decidedzone_id = null;
        if (list != null && list.size() > 0) {
            decidedzone_id = list.get(0);
        }
        session.getTransaction().commit();
        session.close();

        return decidedzone_id;
    }
}

4.在web.xml中配置spring框架的一个Servlet

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <display-name></display-name>    
 <servlet>
    <servlet-name>remoting</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
 </servlet>
 <servlet-mapping>
    <servlet-name>remoting</servlet-name>
    <url-pattern>/remoting/*</url-pattern>
  </servlet-mapping>
 
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

5.在WEB-INF目录下提供配置文件remoting-servlet.xml,注册服务

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx.xsd">
    <!-- 业务类  -->
    <bean id="customerService" class="cn.rodge.crm.service.impl.CustomerServiceImpl" />
    
    <!-- 注册hessian服务 -->
    <bean id="/customer" class="org.springframework.remoting.caucho.HessianServiceExporter">
        <!-- 业务接口实现类 -->
        <property name="service" ref="customerService" />
        <!-- 业务接口 -->
        <property name="serviceInterface" value="cn.rodge.crm.service.CustomerService" />
    </bean>
</beans>

二. 在客户端

1. 导入hessian的jar包

2. 在项目同提供一个接口, 与服务端中提供的接口一致. 如果服务单有向客户端传递自定义类, 则也需要在客户端进行相应的配置

package cn.rodge.crm.service;
import java.util.List;
import cn.rodge.crm.domain.Customer;
// 客户服务接口
public interface CustomerService {
    // 未关联定区客户
    public List<Customer> findnoassociationCustomers();
    // 查询已经关联指定定区的客户
    public List<Customer> findhasassociationCustomers(String decidedZoneId);
    // 将未关联定区客户关联到定区上
    public void assignCustomersToDecidedZone(Integer[] customerIds, String decidedZoneId);
    // 根据电话查询客户
    public List<Customer> findCustomerByTelephone (String telephone);
    //根据地址查询定区id
    public String findDecidedZoneByAddress (String address);
}

package cn.rodge.crm.domain;
import java.io.Serializable;
public class Customer implements Serializable {
    private Integer id;
    private String name;
    private String station;
    private String telephone;
    private String address;
    private String decidedzone_id;
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getStation() {
        return station;
    }
    public void setStation(String station) {
        this.station = station;
    }
    public String getTelephone() {
        return telephone;
    }
    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }
    public String getAddress() {
        return address;
    }
    public void setAddress(String address) {
        this.address = address;
    }
    public String getDecidedzone_id() {
        return decidedzone_id;
    }
    public void setDecidedzone_id(String decidedzone_id) {
        this.decidedzone_id = decidedzone_id;
}

3. 在spring的applicationContext.xml中配置一个代理对象

<bean id="customerService" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
        <property name="serviceInterface" value="cn.rodge.crm.service.CustomerService"></property>
        <property name="serviceUrl" value="http://localhost:8080/crm/remoting/customer"></property>
    </bean>

4.通过注解, 将这个代理对象注入给相应的类

  //注入hessian中的customerService
    @Resource
    private CustomerService customerService;

hessian在ssh项目中的配置的更多相关文章

  1. SiteMesh在项目中的配置

    SiteMesh在项目中的配置 首先在web.xml里面增加siteMesh的配置: <filter> <filter-name>sitemesh</filter-nam ...

  2. Memcached的配置,SSH项目中的整合(com.whalin),Memcached工具类,Memcached的代码调用

     1 修改pom.xml,添加依赖文件: <dependency> <groupId>com.whalin</groupId> <artifactId&g ...

  3. 在SSH项目中实现分页效果

    在实现分页的时候,我使用的是数据库下面的User表,实现的效果是通过分页查询 能够将表中的数据分页显示,点击相关的按钮实现:首页.上一页.下一页.末页的显示 1新建一个dynamic web proj ...

  4. log4j java项目中的配置

    第一步你需要 相关的jar包 第二歩你需要一个关于log4j的配置文件 第三歩 你需要一个检测用的java 文件 导入这两个jar包进你的项目中 commons-logging.jar log4j-1 ...

  5. ORM Nhibernate框架在项目中的配置

    在项目中使用 Nhibernet 时,一定要将 配置文件 .xml  编译方式设置为 嵌入式资源,否则在运行项目时就会出现错误. 以下是hibernate.cfg.xml 的配置,在配置中使用的是 M ...

  6. SSH 项目中 使用websocket 实现网页聊天功能

    参考文章  :java使用websocket,并且获取HttpSession,源码分析    http://www.cnblogs.com/zhuxiaojie/p/6238826.html 1.在项 ...

  7. Android开发:《Gradle Recipes for Android》阅读笔记(翻译)2.5——在项目中共享配置

    问题: 取出多个模块下相同的配置 解决方案: 在顶级gradle配置文件里面使用allprojects或者subprojects块 讨论: 当你在android studio中新建android项目时 ...

  8. vue项目中全局配置变量

    在项目中api管理需要用到全局变量,创建全局变量的方式也有很多. 1.通过export default const BASEURL = "http://localhost:3333/&quo ...

  9. SSH 项目中 用Hibernate底层 简单的封装DAO层

    废话不多少了,主要是使用hibernate的查询方法,自己封装了DAO层,供service来方便使用. 首先:必须要继承的 public class CommonDao extends Hiberna ...

随机推荐

  1. NumberProgressBar开源项目学习

    1.概述 多看多学涨姿势, github真是个宝库 这个项目主要是实现数字进度条效果 github地址在https://github.com/daimajia/NumberProgressBar 感谢 ...

  2. OpenCV 透视变换实例

    参考文献: http://www.cnblogs.com/self-control/archive/2013/01/18/2867022.html http://opencv-code.com/tut ...

  3. Android服务器——使用TomCat实现软件的版本检测,升级,以及下载更新进度!

    Android服务器--使用TomCat实现软件的版本检测,升级,以及下载更新进度! 算下来,TomCat服务器已经写了很长一段时间了,一直说拿他来搞点事 情,也一直没做,今天刚好有空,交流群还有人请 ...

  4. IP网际协议 - IP首部,IP路由选择,子网掩码

    IP首部 4个字节的32 bit值以下面的次序传输:首先是0-7 bit,其次8-15 bit,然后1 6-23 bit,最后是24~31 bit.这种传输次序称作big endian字节序.由于T ...

  5. Oracle EBS 预警系统管理(可用于配置工作流发审批邮件)

    本章主要讲述配置和设置Oracle EBS预警系统管理, 它比较方便和及时发用户或系统对数据库操作情况.下面讲一操作步聚: 1.预警系统管理-->系统-->选项 名称"Unix ...

  6. 【Android 应用开发】BluetoothDevice详解

    一. BluetoothDevice简介 1. 继承关系 public static Class BluetoothDevice extends Object implement Parcelable ...

  7. The 6th tip of DB Query Analyzer

      The 6th tip of DB Query Analyzer MA Gen feng (Guangdong Unitoll Services incorporated, Guangzhou ...

  8. VueJs(5)---V-bind指令

    V-bind指令 一.概述 v-bind  主要用于属性绑定,比方你的class属性,style属性,value属性,href属性等等,只要是属性,就可以用v-bind指令进行绑定. 示例: < ...

  9. [ SSH框架 ] Hibernate框架学习之三

    一.表关系的分析 Hibernate框架实现了ORM的思想,将关系数据库中表的数据映射成对象,使开发人员把对数据库的操作转化为对对象的操作,Hibernate的关联关系映射主要包括多表的映射配置.数据 ...

  10. javascript初学者必须注意的7个细节

    [IT168 技术]每种语言都有它特别的地方,对于JavaScript来说,使用var就可以声明任意类型的变量,这门脚本语言看起来很简单,然而想要写出优雅的代码却是需要不断积累经验的.本文列举Java ...