`

java 树形结构设计(一) Struts + Hibernate

    博客分类:
  • JAVA
阅读更多

该树形结构是一颗关于地理信息的一颗树:

step 1、构建数据库(cteate_table_sql)
/*==============================================================*/
/* Table: DIM_GEOGRAPHY                                         */
/*==============================================================*/
create table DIM_GEOGRAPHY (
   ID                                                    integer              not null,
   GEOGRAPHY_CODE                 VARCHAR(32)          not null,
   GEOGRAPHY_NAME                  VARCHAR(32)          not null,
   GEOGRAPHY_NAME_EN          VARCHAR(32)          null,
   GEOGRAPHY_LEVEL                 integer              not null,
   CITY_TYPE1                                 integer              not null,
   CITY_TYPE2                                 integer              null,
   GEO_TREE_CODE                    VARCHAR(32)          null,
   PARENT_GEOGRAPHY_ID      VARCHAR(32)          null,
   USAGE_FLAG                              VARCHAR(2)           not null,
   CREATE_BY                                 VARCHAR(32)          not null,
   CREATE_DATE                            VARCHAR(30)          not null,
   LASTUPDATE_BY                        VARCHAR(32)          not null,
   LASTUPDATE_DATE                   VARCHAR(30)          not null,
   constraint PK_DIM_GEOGRAPHY primary key  (ID),
   constraint FK_993 foreign key (CITY_TYPE2)
      references DIM_DICT_ITEM (ID),
   constraint FK_333 foreign key (CITY_TYPE1)
      references DIM_DICT_ITEM (ID)
)
go

 其中DIM_DICT_ITEM是一个数据字典表,存一些系统中常用数据,在这里存储城市类型。

 step 2、构建Hibernate PO

/*========================================================================================*/
/* Bean: DimGeography                                       */
/*========================================================================================*/

java 代码
  1. /*  
  2.  * Created Mon Oct 16 14:07:33 CST 2006 by MyEclipse Hibernate Tool.  
  3.  */    
  4. package com.fzfx88.po.base;   
  5.   
  6. import java.io.Serializable;   
  7.   
  8. import com.winchannel.base.service.GeographyService;   
  9.   
  10. /**  
  11.  * A class that represents a row in the 'DIM_GEOGRAPHY' table.   
  12.  * This class may be customized as it is never re-generated   
  13.  * after being created.  
  14.  */  
  15. public class DimGeography   
  16.     extends AbstractDimGeography   
  17.     implements Serializable   
  18. {   
  19.     /**  
  20.      * Simple constructor of DimGeography instances.  
  21.      */  
  22.     public DimGeography()   
  23.     {   
  24.     }   
  25.   
  26.     /**  
  27.      * Constructor of DimGeography instances given a simple primary key.  
  28.      * @param id  
  29.      */  
  30.     public DimGeography(java.lang.Integer id)   
  31.     {   
  32.         super(id);   
  33.     }   
  34.   
  35.     /* Add customized code below */  
  36.     private DimGeography country;   
  37.     private DimGeography province;   
  38.     private DimGeography city;   
  39.     private Integer countryId;   
  40.     private Integer provinceId;   
  41.     private Integer cityId;   
  42.     private String countryName;   
  43.     private String provinceName;   
  44.     private String cityName;   
  45.        
  46.        
  47.     public void getParents(){   
  48.         String treeCode = this.getGeoTreeCode();   
  49.         int i = treeCode.length()/3;   
  50.         GeographyService gService =new  GeographyService();   
  51. //      if(i>=1){   
  52. //          country= gService.retrieveOrgByTreeCode(treeCode,1);   
  53. //          this.countryId = country.getId();   
  54. //          this.countryName =country.getGeographyName();   
  55. //      }   
  56.         if(i>=1){   
  57.             province= gService.retrieveOrgByTreeCode(treeCode,1);   
  58.             if(province!=null){   
  59.                 this.provinceId = province.getId();   
  60.                 this.provinceName =province.getGeographyName();   
  61.             }   
  62.                
  63.         }   
  64.         if(i>=2){   
  65.             city= gService.retrieveOrgByTreeCode(treeCode,2);   
  66.             if(city !=null){   
  67.                 this.cityId = city.getId();   
  68.                 this.cityName =city.getGeographyName();   
  69.             }   
  70.                
  71.         }   
  72.            
  73.     }   
  74.     /**  
  75.      * @return Returns the cityId.  
  76.      */  
  77.     public Integer getCityId() {   
  78.         return cityId;   
  79.     }   
  80.   
  81.     /**  
  82.      * @param cityId The cityId to set.  
  83.      */  
  84.     public void setCityId(Integer cityId) {   
  85.         this.cityId = cityId;   
  86.     }   
  87.   
  88.     /**  
  89.      * @return Returns the cityName.  
  90.      */  
  91.     public String getCityName() {   
  92.         return cityName;   
  93.     }   
  94.   
  95.     /**  
  96.      * @param cityName The cityName to set.  
  97.      */  
  98.     public void setCityName(String cityName) {   
  99.         this.cityName = cityName;   
  100.     }   
  101.   
  102.     /**  
  103.      * @return Returns the countryId.  
  104.      */  
  105.     public Integer getCountryId() {   
  106.         return countryId;   
  107.     }   
  108.   
  109.     /**  
  110.      * @param countryId The countryId to set.  
  111.      */  
  112.     public void setCountryId(Integer countryId) {   
  113.         this.countryId = countryId;   
  114.     }   
  115.   
  116.     /**  
  117.      * @return Returns the countryName.  
  118.      */  
  119.     public String getCountryName() {   
  120.         return countryName;   
  121.     }   
  122.   
  123.     /**  
  124.      * @param countryName The countryName to set.  
  125.      */  
  126.     public void setCountryName(String countryName) {   
  127.         this.countryName = countryName;   
  128.     }   
  129.   
  130.     /**  
  131.      * @return Returns the provinceId.  
  132.      */  
  133.     public Integer getProvinceId() {   
  134.         return provinceId;   
  135.     }   
  136.   
  137.     /**  
  138.      * @param provinceId The provinceId to set.  
  139.      */  
  140.     public void setProvinceId(Integer provinceId) {   
  141.         this.provinceId = provinceId;   
  142.     }   
  143.   
  144.     /**  
  145.      * @return Returns the provinceName.  
  146.      */  
  147.     public String getProvinceName() {   
  148.         return provinceName;   
  149.     }   
  150.   
  151.     /**  
  152.      * @param provinceName The provinceName to set.  
  153.      */  
  154.     public void setProvinceName(String provinceName) {   
  155.         this.provinceName = provinceName;   
  156.     }   
  157.   
  158.     /**  
  159.      * @return Returns the city.  
  160.      */  
  161.     public DimGeography getCity() {   
  162.         return city;   
  163.     }   
  164.   
  165.     /**  
  166.      * @param city The city to set.  
  167.      */  
  168.     public void setCity(DimGeography city) {   
  169.         this.city = city;   
  170.     }   
  171.   
  172.     /**  
  173.      * @return Returns the country.  
  174.      */  
  175.     public DimGeography getCountry() {   
  176.         return country;   
  177.     }   
  178.   
  179.     /**  
  180.      * @param country The country to set.  
  181.      */  
  182.     public void setCountry(DimGeography country) {   
  183.         this.country = country;   
  184.     }   
  185.   
  186.     /**  
  187.      * @return Returns the province.  
  188.      */  
  189.     public DimGeography getProvince() {   
  190.         return province;   
  191.     }   
  192.   
  193.     /**  
  194.      * @param province The province to set.  
  195.      */  
  196.     public void setProvince(DimGeography province) {   
  197.         this.province = province;   
  198.     }   
  199. }   

/*========================================================================================*/
/* Bean: AbstractDimGeography                                      */
/*========================================================================================*/

java 代码
  1. /*  
  2.  * WARNING: DO NOT EDIT THIS FILE. This is a generated file that is synchronized  
  3.  * by MyEclipse Hibernate tool integration.  
  4.  *  
  5.  * Created Mon Oct 16 14:07:33 CST 2006 by MyEclipse Hibernate Tool.  
  6.  */  
  7. package com.fzfx88.po.base;   
  8.   
  9. import java.io.Serializable;   
  10.   
  11. /**  
  12.  * A class that represents a row in the DIM_GEOGRAPHY table.   
  13.  * You can customize the behavior of this class by editing the class, {@link DimGeography()}.  
  14.  * WARNING: DO NOT EDIT THIS FILE. This is a generated file that is synchronized  
  15.  * by MyEclipse Hibernate tool integration.  
  16.  */  
  17. public abstract class AbstractDimGeography    
  18.     implements Serializable   
  19. {   
  20.     /** The cached hash code value for this instance.  Settting to 0 triggers re-calculation. */  
  21.     private int hashValue = 0;   
  22.   
  23.     /** The composite primary key value. */  
  24.     private java.lang.Integer id;   
  25.   
  26.     private java.util.Set childGeo;   
  27.        
  28.     /** The value of the dimDistrSet one-to-many association. */  
  29.     private java.lang.String geoTreeCode;   
  30.   
  31.     /** The value of the dimDistrSet one-to-many association. */  
  32.     private java.util.Set dimDistrSet;   
  33.   
  34.     /** The value of the dimStoreSet one-to-many association. */  
  35.     private java.util.Set dimStoreSet;   
  36.   
  37.     /** The value of the simple geographyCode property. */  
  38.     private java.lang.String geographyCode;   
  39.   
  40.     /** The value of the simple geographyName property. */  
  41.     private java.lang.String geographyName;   
  42.        
  43.     /** The value of the simple geographyNameEn property. */  
  44.     private java.lang.String geographyNameEn;   
  45.        
  46.     /** The value of the simple geographyLevel property. */  
  47.     private java.lang.Integer geographyLevel;   
  48.   
  49.     /** The value of the simple cityLevel property. */  
  50.     private DimDictItem cityType1;   
  51.   
  52.     /** The value of the simple cityLevel property. */  
  53.     private DimDictItem cityType2;   
  54.        
  55.     /** The value of the simple parentGeographyId property. */  
  56.     private java.lang.Integer parentGeographyId;   
  57.   
  58.     /** The value of the simple usageFlag property. */  
  59.     private java.lang.String usageFlag;   
  60.   
  61.     /** The value of the simple createBy property. */  
  62.     private java.lang.String createBy;   
  63.   
  64.     /** The value of the simple createDate property. */  
  65.     private java.lang.String createDate;   
  66.   
  67.     /** The value of the simple lastupdateBy property. */  
  68.     private java.lang.String lastupdateBy;   
  69.   
  70.     /** The value of the simple lastupdateDate property. */  
  71.     private java.lang.String lastupdateDate;   
  72.        
  73.     private Integer parentGeo;   
  74.   
  75.     /**  
  76.      * Simple constructor of AbstractDimGeography instances.  
  77.      */  
  78.     public AbstractDimGeography()   
  79.     {   
  80.     }   
  81.   
  82.     /**  
  83.      * Constructor of AbstractDimGeography instances given a simple primary key.  
  84.      * @param id  
  85.      */  
  86.     public AbstractDimGeography(java.lang.Integer id)   
  87.     {   
  88.         this.setId(id);   
  89.     }   
  90.   
  91.     /**  
  92.      * Return the simple primary key value that identifies this object.  
  93.      * @return java.lang.Integer  
  94.      */  
  95.     public java.lang.Integer getId()   
  96.     {   
  97.         return id;   
  98.     }   
  99.   
  100.     /**  
  101.      * Set the simple primary key value that identifies this object.  
  102.      * @param id  
  103.      */  
  104.     public void setId(java.lang.Integer id)   
  105.     {   
  106.         this.hashValue = 0;   
  107.         this.id = id;   
  108.     }   
  109.   
  110.     /**  
  111.      * Return the value of the GEOGRAPHY_CODE column.  
  112.      * @return java.lang.String  
  113.      */  
  114.     public java.lang.String getGeographyCode()   
  115.     {   
  116.         return this.geographyCode;   
  117.     }   
  118.   
  119.     /**  
  120.      * Set the value of the GEOGRAPHY_CODE column.  
  121.      * @param geographyCode  
  122.      */  
  123.     public void setGeographyCode(java.lang.String geographyCode)   
  124.     {   
  125.         this.geographyCode = geographyCode;   
  126.     }   
  127.   
  128.     /**  
  129.      * Return the value of the GEOGRAPHY_NAME column.  
  130.      * @return java.lang.String  
  131.      */  
  132.     public java.lang.String getGeographyName()   
  133.     {   
  134.         return this.geographyName;   
  135.     }   
  136.   
  137.     /**  
  138.      * Set the value of the GEOGRAPHY_NAME column.  
  139.      * @param geographyName  
  140.      */  
  141.     public void setGeographyName(java.lang.String geographyName)   
  142.     {   
  143.         this.geographyName = geographyName;   
  144.     }   
  145.   
  146.     /**  
  147.      * Return the value of the GEOGRAPHY_LEVEL column.  
  148.      * @return java.lang.Integer  
  149.      */  
  150.     public java.lang.Integer getGeographyLevel()   
  151.     {   
  152.         return this.geographyLevel;   
  153.     }   
  154.   
  155.     /**  
  156.      * Set the value of the GEOGRAPHY_LEVEL column.  
  157.      * @param geographyLevel  
  158.      */  
  159.     public void setGeographyLevel(java.lang.Integer geographyLevel)   
  160.     {   
  161.         this.geographyLevel = geographyLevel;   
  162.     }   
  163.   
  164.     /**  
  165.      * Return the value of the CITY_LEVEL column.  
  166.      * @return java.lang.Integer  
  167.      */  
  168.     public DimDictItem getCityType1()   
  169.     {   
  170.         return this.cityType1;   
  171.     }   
  172.   
  173.     /**  
  174.      * Set the value of the CITY_LEVEL column.  
  175.      * @param cityLevel  
  176.      */  
  177.     public void setCityType1(DimDictItem cityType1)   
  178.     {   
  179.         this.cityType1 = cityType1;   
  180.     }   
  181.   
  182.     /**  
  183.      * Return the value of the PARENT_GEOGRAPHY_ID column.  
  184.      * @return java.lang.Integer  
  185.      */  
  186.     public java.lang.Integer getParentGeographyId()   
  187.     {   
  188.         return this.parentGeographyId;   
  189.     }   
  190.   
  191.     /**  
  192.      * Set the value of the PARENT_GEOGRAPHY_ID column.  
  193.      * @param parentGeographyId  
  194.      */  
  195.     public void setParentGeographyId(java.lang.Integer parentGeographyId)   
  196.     {   
  197.         this.parentGeographyId = parentGeographyId;   
  198.     }   
  199.   
  200.     /**  
  201.      * Return the value of the USAGE_FLAG column.  
  202.      * @return java.lang.String  
  203.      */  
  204.     public java.lang.String getUsageFlag()   
  205.     {   
  206.         return this.usageFlag;   
  207.     }   
  208.   
  209.     /**  
  210.      * Set the value of the USAGE_FLAG column.  
  211.      * @param usageFlag  
  212.      */  
  213.     public void setUsageFlag(java.lang.String usageFlag)   
  214.     {   
  215.         this.usageFlag = usageFlag;   
  216.     }   
  217.   
  218.     /**  
  219.      * Return the value of the CREATE_BY column.  
  220.      * @return java.lang.String  
  221.      */  
  222.     public java.lang.String getCreateBy()   
  223.     {   
  224.         return this.createBy;   
  225.     }   
  226.   
  227.     /**  
  228.      * Set the value of the CREATE_BY column.  
  229.      * @param createBy  
  230.      */  
  231.     public void setCreateBy(java.lang.String createBy)   
  232.     {   
  233.         this.createBy = createBy;   
  234.     }   
  235.   
  236.     /**  
  237.      * Return the value of the CREATE_DATE column.  
  238.      * @return java.lang.String  
  239.      */  
  240.     public java.lang.String getCreateDate()   
  241.     {   
  242.         return this.createDate;   
  243.     }   
  244.   
  245.     /**  
  246.      * Set the value of the CREATE_DATE column.  
  247.   &
  • 大小: 28.4 KB
  • 大小: 28.4 KB
分享到:
评论
1 楼 379548695 2007-07-18  
老大你有正个源码给我发下好不?

相关推荐

Global site tag (gtag.js) - Google Analytics