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

step 6、 Struts Action 类

java 代码
  1. /**  
  2.  * 地理信息  
  3.  */  
  4. package com.fzfx88.base.action;   
  5.   
  6. import java.util.ArrayList;   
  7. import java.util.List;   
  8.   
  9. import javax.servlet.http.HttpServletRequest;   
  10. import javax.servlet.http.HttpServletResponse;   
  11.   
  12. import org.apache.log4j.Logger;   
  13. import org.apache.struts.action.ActionForm;   
  14. import org.apache.struts.action.ActionForward;   
  15. import org.apache.struts.action.ActionMapping;   
  16.   
  17. import com.fzfx88.base.form.GeographyForm;   
  18. import com.fzfx88.base.service.DictService;   
  19. import com.fzfx88.base.service.GeographyService;   
  20. import com.fzfx88.common.Constants;   
  21. import com.fzfx88.common.UserInfo;   
  22. import com.fzfx88.common.base.BaseAction;   
  23. import com.fzfx88.po.base.DimGeography;   
  24.   
  25. /**  
  26.  * @author huguoqing  
  27.  *  
  28.  */  
  29. public class GeographyAction extends BaseAction {   
  30.     public static Logger log=Logger.getLogger(GeographyAction.class);   
  31.     /**  
  32.      * 地理信息树结构初始化参数设置  
  33.      * @param mapping  
  34.      * @param form  
  35.      * @param request  
  36.      * @param response  
  37.      * @return ActionForward  
  38.      */  
  39.     public ActionForward inittree(ActionMapping mapping,ActionForm form,   
  40.             HttpServletRequest request,HttpServletResponse response){   
  41.         return mapping.findForward("inittree");   
  42.     }   
  43.     /**  
  44.      * 地理信息初始化  
  45.      * @param mapping  
  46.      * @param form  
  47.      * @param request  
  48.      * @param response  
  49.      * @return  
  50.      */  
  51.     public ActionForward init(ActionMapping mapping,ActionForm form,   
  52.             HttpServletRequest request,HttpServletResponse response){   
  53.         GeographyForm gForm = (GeographyForm)form;   
  54.         DimGeography po = gForm.getGeography();   
  55.            
  56.         GeographyService gService = new GeographyService();   
  57.         DictService dService = new DictService();   
  58.         /**取得cityType和cityType2列表**/  
  59.         List cityList1 = dService.queryDictItem(Constants.CITY_TYPE1,true);   
  60.         List cityList2 = dService.queryDictItem(Constants.CITY_TYPE2,true);   
  61.         gForm.setCityTypeList1(cityList1);   
  62.         gForm.setCityTypeList2(cityList2);   
  63.         /**取得当前节点下所有字节点**/  
  64.         List geographyList = new ArrayList();   
  65.         if(gForm.getGeographyID()!=null&&!gForm.getGeographyID().equals("")){   
  66.             int geographyId = Integer.parseInt(gForm.getGeographyID());   
  67.             String usageFlag = "1";   
  68.             geographyList = gService.queryGeographyByParentId(geographyId,usageFlag);              
  69.         }   
  70.         gForm.setGeographyList(geographyList);   
  71.         /**根据页面传来的地理信息id,获得对应地理信的相关信息**/  
  72.         if(gForm.getId()!=null&&!gForm.getId().equals("")){   
  73.             po = gService.queryGeography(Integer.valueOf(gForm.getId()));   
  74.         }   
  75.         gForm.setGeography(po);   
  76.         return mapping.findForward("init");   
  77.     }   
  78.     /**  
  79.      * 新增地理信息  
  80.      * @param mapping  
  81.      * @param form  
  82.      * @param request  
  83.      * @param response  
  84.      * @return  
  85.      */  
  86.     public ActionForward create(ActionMapping mapping,ActionForm form,   
  87.             HttpServletRequest request,HttpServletResponse response){   
  88.         GeographyForm gForm = (GeographyForm)form;   
  89.         DimGeography po = gForm.getGeography();   
  90.         GeographyService gService = new GeographyService();   
  91.         UserInfo user = this.getCurrentUser(request);   
  92.            
  93.         /**  
  94.          * 设置po的treeCode  
  95.          */        
  96.         if(gForm.getGeographyID()!=null&&!gForm.getGeographyID().equals("")){   
  97.             String parentId = gForm.getGeographyID();   
  98.             /**取得当前节点对应的 地理信息类**/  
  99.             DimGeography graphy = gService.queryGeography(Integer.valueOf(parentId));    
  100.             /**设置GeographyLevel**/  
  101.             String level = String.valueOf(graphy.getGeographyLevel().intValue()+1);   
  102.             po.setGeographyLevel(Integer.valueOf(level));   
  103.             /**取得当前节点的treeCode**/  
  104.             String treeCode = graphy.getGeoTreeCode();   
  105.                
  106.             String usageFlag = "1";   
  107.             /**取得当前节点下所有字节点列表**/  
  108.             List childGeo = gService.queryGeographyByParentId(Integer.parseInt(parentId),usageFlag);   
  109.             if(childGeo.isEmpty()){   
  110.                 po.setGeoTreeCode(treeCode+"001");   
  111.             }else{   
  112.                 /**取得当前子列表里面treeCode最大的节点**/  
  113.                 DimGeography maxGraphy = (DimGeography)childGeo.get(0);   
  114.                 /**取得当前最大子节点的treeCode**/  
  115.                 String maxBrothorTreeCode = maxGraphy.getGeoTreeCode();   
  116.                 /**将当前treeCode拆分为俩个字符串**/  
  117.                 String subFirstTreeCode = maxBrothorTreeCode.substring(0,maxBrothorTreeCode.length()-3);   
  118.                 String subSecondTreeCode = maxBrothorTreeCode.substring(maxBrothorTreeCode.length()-3,maxBrothorTreeCode.length());   
  119.                 String currentCode = String.valueOf(1000 + Integer.parseInt(subSecondTreeCode) + 1);   
  120.                 String newTreeCode = currentCode.substring(1,currentCode.length());   
  121.                 String poTreeCode =subFirstTreeCode + newTreeCode;   
  122.                 po.setGeoTreeCode(poTreeCode);   
  123.             }   
  124.         }   
  125.         /**设置po的父id**/  
  126.         DictService dictService = new DictService();   
  127.         po.setParentGeographyId(Integer.valueOf(gForm.getGeographyID()));   
  128.         po.setParentGeo(Integer.valueOf(gForm.getGeographyID()));   
  129.         if(gForm.getCityType1()!=null&&!gForm.getCityType1().equals("")){   
  130.             po.setCityType1(dictService.retrieveDictitem(gForm.getCityType1()));   
  131.                
  132.         }   
  133.         if(gForm.getCityType1()!=null&&!gForm.getCityType1().equals("")){   
  134.             po.setCityType2(dictService.retrieveDictitem(gForm.getCityType2()));   
  135.                
  136.         }   
  137.         /********字符处理***********/  
  138.         String geoName = po.getGeographyName();   
  139.         String newGeoName = geoName.replace('\'','’').trim();   
  140.         po.setGeographyName(newGeoName);   
  141.         String geoNameEN = po.getGeographyNameEn();   
  142.         String newGeoNameEN = geoNameEN.replace('\'','’').trim();   
  143.         po.setGeographyNameEn(newGeoNameEN);   
  144.         String geoCode = po.getGeographyCode();   
  145.         String newGeoCode = geoCode.replace('\'','’').trim();   
  146.         po.setGeographyCode(newGeoCode);   
  147.         /********数据提交*************/  
  148.         gService.createGeography(po,user);   
  149.         return mapping.findForward("success");   
  150.     }   
  151.     /**  
  152.      * 修改地理信息  
  153.      * @param mapping  
  154.      * @param form  
  155.      * @param request  
  156.      * @param response  
  157.      * @return  
  158.      */  
  159.     public ActionForward modify(ActionMapping mapping,ActionForm form,   
  160.             HttpServletRequest request,HttpServletResponse response){   
  161.         GeographyForm gForm = (GeographyForm)form;   
  162.         UserInfo user = this.getCurrentUser(request);   
  163.         DimGeography po = gForm.getGeography();   
  164.         GeographyService gService = new GeographyService();   
  165.         DimGeography vo = gService.queryGeography(Integer.valueOf(gForm.getListId()));   
  166.         vo.setGeographyName(po.getGeographyName().replace('\'','’').trim());   
  167.         vo.setGeographyNameEn(po.getGeographyNameEn().replace('\'','’').trim());   
  168.         vo.setGeographyCode(po.getGeographyCode().replace('\'','’').trim());   
  169.         DictService dictService = new DictService();   
  170.         if(gForm.getCityType1()!=null&&!gForm.getCityType1().equals("")){   
  171.             vo.setCityType1(dictService.retrieveDictitem(gForm.getCityType1()));   
  172.                
  173.         }   
  174.         if(gForm.getCityType2()!=null&&!gForm.getCityType2().equals("")){   
  175.             vo.setCityType2(dictService.retrieveDictitem(gForm.getCityType2()));   
  176.                
  177.         }   
  178.         gService.updateGeography(vo,user);   
  179.         return mapping.findForward("success");   
  180.     }   
  181.     /**  
  182.      * 作废地理信息  
  183.      * @param mapping  
  184.      * @param form  
  185.      * @param request  
  186.      * @param response  
  187.      * @return  
  188.      */  
  189.     public ActionForward delete(ActionMapping mapping,ActionForm form,   
  190.             HttpServletRequest request,HttpServletResponse response){   
  191.         GeographyForm gForm = (GeographyForm)form;   
  192.         UserInfo user = this.getCurrentUser(request);   
  193. //      DimGeography po = gForm.getGeography();   
  194.         GeographyService gService = new GeographyService();   
  195.         DimGeography vo = gService.queryGeography(Integer.valueOf(gForm.getListId()));   
  196.         String usageFlag = "0";   
  197.         vo.setUsageFlag(usageFlag);   
  198.         gService.updateGeography(vo,user);   
  199.         return mapping.findForward("success");   
  200.     }   
  201. }   

step 7、Form 类

java 代码
  1. /**  
  2.  * 地理信息  
  3.  */  
  4. package com.winchannel.base.form;   
  5.   
  6. import java.util.List;   
  7. import com.winchannel.common.base.BaseForm;   
  8. import com.winchannel.po.base.DimGeography;   
  9. /**  
  10.  * @author huguoqing  
  11.  *  
  12.  */  
  13. public class GeographyForm extends BaseForm {   
  14.     private DimGeography geography = new DimGeography();   
  15.        
  16.     private List geographyList;   
  17.     private String geographyTypeID;    
  18.     private List   cityTypeList1;   
  19.     private String cityType1;      
  20.     private List   cityTypeList2;   
  21.     private String cityType2;      
  22.     private String geographyID;//页面传来的 id值   
  23.     private String graphyName;   
  24.     private String graphyNameEn;   
  25.     private String graphyCode;   
  26.     private String cityLevel;   
  27.     private String graphyLevel;   
  28.     private String id;   
  29.     private String state;   
  30.     private String listId;   
  31.        
  32.   
  33.     /**  
  34.      * @return Returns the state.  
  35.      */  
  36.     public String getState() {   
  37.         return state;   
  38.     }   
  39.   
  40.     /**  
  41.      * @param state The state to set.  
  42.      */  
  43.     public void setState(String state) {   
  44.         this.state = state;   
  45.     }   
  46.   
  47.     /**  
  48.      * @return Returns the geography.  
  49.      */  
  50.     public DimGeography getGeography() {   
  51.         return geography;   
  52.     }   
  53.   
  54.     /**  
  55.      * @param geography The geography to set.  
  56.      */  
  57.     public void setGeography(DimGeography geography) {   
  58.         this.geography = geography;   
  59.     }   
  60.   
  61.     /**  
  62.      * @return Returns the id.  
  63.      */  
  64.     public String getId() {   
  65.         return id;   
  66.     }   
  67.   
  68.     /**  
  69.      * @param id The id to set.  
  70.      */  
  71.     public void setId(String id) {   
  72.         this.id = id;   
  73.     }   
  74.   
  75.     /**  
  76.      * @return Returns the cityLevel.  
  77.      */  
  78.     public String getCityLevel() {   
  79.         return cityLevel;   
  80.     }   
  81.   
  82.     /**  
  83.      * @param cityLevel The cityLevel to set.  
  84.      */  
  85.     public void setCityLevel(String cityLevel) {   
  86.         this.cityLevel = cityLevel;   
  87.     }   
  88.   
  89.     /**  
  90.      * @return Returns the graphyCode.  
  91.      */  
  92.     public String getGraphyCode() {   
  93.         return graphyCode;   
  94.     }   
  95.   
  96.     /**  
  97.      * @param graphyCode The graphyCode to set.  
  98.      */  
  99.     public void setGraphyCode(String graphyCode) {   
  100.         this.graphyCode = graphyCode;   
  101.     }   
  102.   
  103.     /**  
  104.      * @return Returns the graphyLevel.  
  105.      */  
  106.     public String getGraphyLevel() {   
  107.         return graphyLevel;   
  108.     }   
  109.   
  110.     /**  
  111.      * @param graphyLevel The graphyLevel to set.  
  112.      */  
  113.     public void setGraphyLevel(String graphyLevel) {   
  114.         this.graphyLevel = graphyLevel;   
  115.     }   
  116.   
  117.     /**  
  118.      * @return Returns the graphyName.  
  119.      */  
  120.     public String getGraphyName() {   
  121.         return graphyName;   
  122.     }   
  123.   
  124.     /**  
  125.      * @param graphyName The graphyName to set.  
  126.      */  
  127.     public void setGraphyName(String graphyName) {   
  128.         this.graphyName = graphyName;   
  129.     }   
  130.     /**  
  131.      * @return Returns the graphyNameEn.  
  132.      */  
  133.     public String getGraphyNameEn() {   
  134.         return graphyNameEn;   
  135.     }   
  136.     /**  
  137.      * @param graphyNameEn The graphyNameEn to set.  
  138.      */  
  139.     public void setGraphyNameEn(String graphyNameEn) {   
  140.         this.graphyNameEn = graphyNameEn;   
  141.     }   
  142.     /**  
  143.      * @return Returns the geographyID.  
  144.      */  
  145.     public String getGeographyID() {   
  146.         return geographyID;   
  147.     }   
  148.     /**  
  149.      * @param geographyID The geographyID to set.  
  150.      */  
  151.     public void setGeographyID(String geographyID) {   
  152.         this.geographyID = geographyID;   
  153.     }   
  154.     /**  
  155.      * @return Returns the geographyList.  
  156.      */  
  157.     public List getGeographyList() {   
  158.         return geographyList;   
  159.     }   
  160.     /**  
  161.      * @param geographyList The geographyList to set.  
  162.      */  
  163.     public void setGeographyList(List geographyList) {   
  164.         this.geographyList = geographyList;   
  165.     }   
  166.     /**  
  167.      * @return Returns the geographyTypeID.  
  168.      */  
  169.     public String getGeographyTypeID() {   
  170.         return geographyTypeID;   
  171.     }   
  172.     /**  
  173.      * @param geographyTypeID The geographyTypeID to set.  
  174.      */  
  175.     public void setGeographyTypeID(String geographyTypeID) {   
  176.         this.geographyTypeID = geographyTypeID;   
  177.     }   
  178.     /**  
  179.      * @return Returns the cityType1.  
  180.      */  
  181.     public String getCityType1() {   
  182.         return cityType1;   
  183.     }   
  184.     /**  
  185.      * @param cityType1 The cityType1 to set.  
  186.      */  
  187.     public void setCityType1(String cityType1) {   
  188.         this.cityType1 = cityType1;   
  189.     }   
  190.     /**  
  191.      * @return Returns the cityType2.  
  192.      */  
  193.     public String getCityType2() {   
  194.         return cityType2;   
  195.     }   
  196.     /**  
  197.      * @param cityType2 The cityType2 to set.  
  198.      */  
  199.     public void setCityType2(String cityType2) {   
  200.         this.cityType2 = cityType2;   
  201.     }   
  202.     /**  
  203.      * @return Returns the cityTypeList1.  
  204.      */  
  205.     public List getCityTypeList1() {   
  206.         return cityTypeList1;   
  207.     }   
  208.     /**  
  209.      * @param cityTypeList1 The cityTypeList1 to set.  
  210.      */  
  211.     public void setCityTypeList1(List cityTypeList1) {   
  212.         this.cityTypeList1 = cityTypeList1;   
  213.     }   
  214.     /**  
  215.      * @return Returns the cityTypeList2.  
  216.      */  
  217.     public List getCityTypeList2() {   
  218.         return cityTypeList2;   
  219.     }   
  220.     /**  
  221.      * @param cityTypeList2 The cityTypeList2 to set.  
  222.      */  
  223.     public void setCityTypeList2(List cityTypeList2) {   
  224.         this.cityTypeList2 = cityTypeList2;   
  225.     }   
  226.     /**  
  227.      * @return Returns the listId.  
  228.      */  
  229.     public String getListId() {   
  230.         return listId;   
  231.     }   
  232.     /**  
  233.      * @param listId The listId to set.  
  234.      */  
  235.     public void setListId(String listId) {   
  236.         
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值