That way I want to stay

          BlogJava 首頁 新隨筆 聯系 聚合 管理
            55 Posts :: 1 Stories :: 41 Comments :: 0 Trackbacks

            我們一般項目中,都是把字典存到數據庫中的。幾個月前在做一個政府的項目中,覺得其實一些字典是跟開發工程緊密結合在一起的,也就是說字典變了,工程肯定也要變,這樣子的字典如果也存到數據庫中的話,也是多增加一些麻煩而已,后來但將這些字典寫成枚舉。然后數據庫里面取的所謂的字典的key就是枚舉的name,如:"unsubmited",而前臺頁面顯示的,就是枚舉的一個屬性text,不過這里用到了webwork里面的ognl語法。

          /**
           * Author: Wingel
           * Date: 2006-7-29
           * Time: 15:17:52
           
          */

          public enum ApplicationState {
              unsubmited(
          "未提交"),submited("提交/待審批"),agreed("通過"),disagreed("未同意");
              
          private String text;

              ApplicationState(String text) 
          {
                  
          this.text = text;
              }


              
          public static String getText(String name) {//給頁面用的方法
                  try {
                      
          return valueOf(name).text;
                  }
           catch (Exception e) {
                      
          return null;
                  }

              }


              
          public String getText() {
                  
          return text;
              }


              
          public static boolean isValidRegisterType(String name) {
                  
          try {
                      valueOf(name);
                      
          return true;
                  }
           catch (Exception e) {
                      
          return false;
                  }

              }


              
          public static ApplicationState[] allState() {
                  
          return ApplicationState.values();
              }


              
          public String getName() {
                  
          return this.name();
              }

          }



           

          文章來源:http://blog.csdn.net/Wingel/archive/2006/11/26/1414837.aspx
          posted on 2006-11-29 11:18 Wingel 閱讀(231) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 吕梁市| 德安县| 阿勒泰市| 龙江县| 定边县| 延长县| 饶阳县| 迁西县| 五原县| 江都市| 永济市| 托里县| 韶关市| 乌拉特中旗| 沙雅县| 简阳市| 三河市| 太保市| 兴文县| 丰镇市| 崇阳县| 略阳县| 桃园市| 鞍山市| 安徽省| 崇州市| 锦屏县| 班玛县| 斗六市| 墨江| 河北区| 大丰市| 永春县| 桐庐县| 辽宁省| 石柱| 道孚县| 襄樊市| 林甸县| 古浪县| 南木林县|