`

使用easyui中的conbox结合ssh注解方式实现省市区三级联动效果

阅读更多
/*
 * Copyright (c) 2012-2032 Accounting Center of China Aviation(ACCA).
 * All Rights Reserved.
 */
package com.acca.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.acca.entity.Area;
import com.acca.service.AreaService;
import com.opensymphony.xwork2.ActionSupport;

/**
 * 
 * 
 * @version sas-web v1.0
 * @author zhouhua, 2013-1-8
 */
@Controller
@Scope("prototype")
public class AreaAction extends ActionSupport {

    private Area area;
    private Integer parentid=0;
    @Resource(name = "areaService")
    private AreaService areaService;
    private List jsonList = new ArrayList();

    /**
     * @return the parentid
     */
    public Integer getParentid() {
        return parentid;
    }

    /**
     * @param parentid the parentid to set
     */
    public void setParentid(Integer parentid) {
        this.parentid = parentid;
    }

    /**
     * @return the jsonList
     */
    public List getJsonList() {
        return jsonList;
    }

    /**
     * @param jsonList the jsonList to set
     */
    public void setJsonList(List jsonList) {
        this.jsonList = jsonList;
    }

    /**
     * @return the area
     */
    public Area getArea() {
        return area;
    }

    /**
     * @param area the area to set
     */
    public void setArea(Area area) {
        this.area = area;
    }

    /**
     * @param areaService the areaService to set
     */
    public void setAreaService(AreaService areaService) {
        this.areaService = areaService;
    }

    /**
     * 形成下拉列表
     * 
     * @return
     */
    @SuppressWarnings("unchecked")
    public String combox() {
        List<Area> list = areaService.findAll(parentid);
        for (Area r : list) {
            Map map = new HashMap();
            map.put("areaid", r.getAreaid());
            map.put("name", r.getName());
            jsonList.add(map);
        }
        return SUCCESS;
    }

}
 
package com.acca.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.acca.entity.Area;
import com.acca.service.AreaService;
import com.opensymphony.xwork2.ActionSupport;

/**
 * 
 * 
 * 
 * @author zhouhua, 2013-1-8
 */
@Controller
@Scope("prototype")
public class AreaAction extends ActionSupport {

    private Area area;
    private Integer parentid=0;
    @Resource(name = "areaService")
    private AreaService areaService;
    private List jsonList = new ArrayList();

    /**
     * @return the parentid
     */
    public Integer getParentid() {
        return parentid;
    }

    /**
     * @param parentid the parentid to set
     */
    public void setParentid(Integer parentid) {
        this.parentid = parentid;
    }

    /**
     * @return the jsonList
     */
    public List getJsonList() {
        return jsonList;
    }

    /**
     * @param jsonList the jsonList to set
     */
    public void setJsonList(List jsonList) {
        this.jsonList = jsonList;
    }

    /**
     * @return the area
     */
    public Area getArea() {
        return area;
    }

    /**
     * @param area the area to set
     */
    public void setArea(Area area) {
        this.area = area;
    }

    /**
     * @param areaService the areaService to set
     */
    public void setAreaService(AreaService areaService) {
        this.areaService = areaService;
    }

    /**
     * 形成下拉列表
     * 
     * @return
     */
    @SuppressWarnings("unchecked")
    public String combox() {
        List<Area> list = areaService.findAll(parentid);
        for (Area r : list) {
            Map map = new HashMap();
            map.put("areaid", r.getAreaid());
            map.put("name", r.getName());
            jsonList.add(map);
        }
        return SUCCESS;
    }

}
 
package com.acca.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.acca.dao.AreaDao;
import com.acca.entity.Area;
import com.acca.entity.PageModel;
import com.acca.service.AreaService;

/**
 * 
 * 
 * 
 * @author zhouhua, 2013-1-8
 */
@Service("areaService")
public class AreaServiceImpl implements AreaService {

    @Resource(name="areaDao")
    private AreaDao areaDao;

    /**
     * @param areaDao the areaDao to set
     */
    public void setAreaDao(AreaDao areaDao) {
        this.areaDao = areaDao;
    }

    /**
     * @return
     * @see com.acca.service.impl.AreaService#findAll()
     */
    @Override
    public List<Area> findAll(Integer parentid) {
        return areaDao.findAll(parentid);
    }

}
 
/*
 * Copyright (c) 2012-2032 Accounting Center of China Aviation(ACCA).
 * All Rights Reserved.
 */
package com.acca.dao.impl;

import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import com.acca.dao.AreaDao;
import com.acca.entity.Area;
import com.acca.entity.PageModel;

/**
 * 
 * 
 * @version sas-web v1.0
 * @author zhouhua, 2013-1-8
 */
@Repository("areaDao")
public class AreaDaoImpl extends HibernateDaoSupport implements AreaDao {
    private SessionFactory sessionFacotry;

    // 注入一个bean, 默认(name = "sessionFactory"), 因此只写@Resource
    @Resource
    public void setSessionFacotry(SessionFactory sessionFacotry) {
        super.setSessionFactory(sessionFacotry);
    }

    /**
     * @return
     * @see com.acca.dao.AreaDao#findAll()
     */
    @Override
    public List<Area> findAll(final Integer parentid) {
        @SuppressWarnings("unchecked")
       List<Area> list = (List<Area>) getHibernateTemplate().execute(new HibernateCallback() {

            @Override
            public Object doInHibernate(Session session) throws HibernateException, SQLException {
                return session.createQuery("from Area a where a.parentid=? order by a.vieworder")
                        .setParameter(0, parentid)
                        .list();

            }
        });
        return list;
    }

}
 
<?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:p="http://www.springframework.org/schema/p"
	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-2.5.xsd
	http://www.springframework.org/schema/tx 
	http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
	http://www.springframework.org/schema/context 
	http://www.springframework.org/schema/context/spring-context-2.5.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
	
<context:component-scan base-package="com.acca"/>
<!-- 配置注解工厂 -->
<bean id="sessionFactory"
	class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
	<property name="configLocation"
		value="classpath:hibernate.cfg.xml">
	</property>
	<!-- 扫描实体 -->
	<property name="packagesToScan">
	 <list>
	  <value>com/acca/entity</value>
	 </list>
	</property>
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
 <property name="sessionFactory">
  <ref local="sessionFactory"/>
 </property>
</bean>
<!-- 配置事务特性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
 <tx:attributes>
  <tx:method name="save*" propagation="REQUIRED"/>
  <tx:method name="update*" propagation="REQUIRED"/>
  <tx:method name="delete*" propagation="REQUIRED"/>
  <tx:method name="*" read-only="false"/>
 </tx:attributes>
</tx:advice>
<!-- 声明哪些包使用事务 -->
<aop:config>
 <aop:pointcut expression="execution(* com.acca.service.*.*(..))" id="allService"/>
 <aop:advisor advice-ref="txAdvice" pointcut-ref="allService"/>
</aop:config>
</beans>
 
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
  <constant name="struts.multipart.saveDir" value="D:/temp"></constant>
  <constant name="struts.devMode" value="true"></constant>
  <package name="struts" extends="struts-default,json-default" namespace="/">
  <action name="combox" class="areaAction" method="combox">
   <result type="json">
    <param name="root">jsonList</param>
   </result>
  </action>
  </package> 
</struts>    
 
package com.acca.entity;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

/**
 * 
 * 
 * 
 * @author zhouhua, 2013-1-8
 */
@Entity
@Table(name="area")
public class Area {

    @Id
    @GeneratedValue
    private Integer areaid;
    private String name;
    private Integer parentid;
    private Integer vieworder;

    /**
     * @return the areaid
     */
    public Integer getAreaid() {
        return areaid;
    }

    /**
     * @param areaid the areaid to set
     */
    public void setAreaid(Integer areaid) {
        this.areaid = areaid;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the parentid
     */
    public Integer getParentid() {
        return parentid;
    }

    /**
     * @param parentid the parentid to set
     */
    public void setParentid(Integer parentid) {
        this.parentid = parentid;
    }

    /**
     * @return the vieworder
     */
    public Integer getVieworder() {
        return vieworder;
    }

    /**
     * @param vieworder the vieworder to set
     */
    public void setVieworder(Integer vieworder) {
        this.vieworder = vieworder;
    }

}
 
分享到:
评论
1 楼 lian 2013-05-13  
少了一张 jsp 代码的页面  求补上!

相关推荐

Global site tag (gtag.js) - Google Analytics