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 閱讀(236) 評論(0)  編輯  收藏

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


          網站導航:
           
          主站蜘蛛池模板: 衡南县| 曲靖市| 芜湖县| 龙陵县| 塘沽区| 景宁| 溆浦县| 波密县| 土默特右旗| 睢宁县| 新余市| 漠河县| 揭阳市| 栾川县| 宝山区| 包头市| 县级市| 靖边县| 隆安县| 呼玛县| 新民市| 土默特左旗| 桃园市| 中卫市| 蓝山县| 大同县| 瑞丽市| 石景山区| 澎湖县| 安阳市| 甘肃省| 泸溪县| 普定县| 齐齐哈尔市| 万宁市| 德昌县| 琼海市| 隆安县| 安福县| 鸡东县| 界首市|