标签:ztree 三级级联 hibernate mysql struts2
zTree实现地市县三级级联DAO接口实现
ProvinceDaoImpl.java:
/** * @Title:ProvinceDaoImpl.java * @Package:com.gwtjs.dao.impl * @Description:省份地市县级三级级联DAO接口实现 * @author:Youhaidong(游海东) * @date:2014-5-10 下午10:40:35 * @version V1.0 */ package com.gwtjs.dao.impl; import java.util.ArrayList; import java.util.List; import org.apache.commons.lang.StringUtils; import org.hibernate.SQLQuery; import org.springframework.stereotype.Repository; import com.gwtjs.dao.ProvinceDao; import com.gwtjs.model.Province; /** * 类功能说明 * 类修改者 修改日期 * 修改说明 * <p>Title:ProvinceDaoImpl.java</p> * <p>Description:游海东个人开发</p> * <p>Copyright:Copyright(c)2013</p> * @author:游海东 * @date:2014-5-10 下午10:40:35 * @version V1.0 */ @Repository(value = "provinceDao") public class ProvinceDaoImpl extends GenericDaoImpl<Province, Long> implements ProvinceDao { /** * * @Title:findArea * @Description: * @param:@param provinceCode 省份编码 * @param:@param cityCode 地市编码 * @param:@param countyCode 县级编码 * @param:@return * @return:List<Province> * @throws */ @SuppressWarnings("unchecked") @Override public List<Province> findArea(String provinceCode, String cityCode,String countyCode) { List<Province> list = new ArrayList<Province>(); StringBuilder sb = new StringBuilder(); sb.append("SELECT t.`province_name`,"); sb.append("t.`city_name`,"); sb.append("t.`county_name` "); sb.append("FROM t_area_tab t "); sb.append("WHERE 1=1 "); //判断省份编码不为空 if(StringUtils.isNotBlank(provinceCode)) { sb.append("AND t.`province_code` = ‘").append(provinceCode).append("‘ "); } //判断地市编码不为空 if(StringUtils.isNotBlank(cityCode)) { sb.append("AND t.`city_code` = ‘").append(cityCode).append("‘ "); } //判断县级编码不为空 if(StringUtils.isNotBlank(countyCode)) { sb.append("AND t.`county_code` = ‘").append(countyCode).append("‘ "); } SQLQuery q = getSession().createSQLQuery(sb.toString()); System.out.println("三级级联SQL语句:" + sb.toString()); List<Object[]> items = q.list(); if(null != items && items.size() > 0) { Province province = null; for(Object[] obj:items) { province = new Province(); /** * 省份名称 */ province.setProvinceName(null == obj[0]?"":obj[0].toString()); /** * 地市名称 */ province.setProvinceName(null == obj[0]?"":obj[0].toString()); /** * 县级名称 */ province.setProvinceName(null == obj[0]?"":obj[0].toString()); list.add(province); } } return list; } }
zTree实现地市县三级级联DAO接口实现,布布扣,bubuko.com
标签:ztree 三级级联 hibernate mysql struts2
原文地址:http://blog.csdn.net/you23hai45/article/details/25514257