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)  編輯  收藏

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


          網站導航:
           
          主站蜘蛛池模板: 镇坪县| 织金县| 平和县| 南皮县| 米泉市| 宜阳县| 马龙县| 积石山| 喀喇沁旗| 南康市| 仁布县| 长沙市| 蕉岭县| 兰州市| 清远市| 通城县| 增城市| 桂林市| 翁牛特旗| 舞阳县| 绥滨县| 宁波市| 开封市| 织金县| 射阳县| 漾濞| 泸定县| 陵川县| 新民市| 如皋市| 乐昌市| 棋牌| 阿克| 丹东市| 海林市| 嘉荫县| 连城县| 会昌县| 祁阳县| 齐河县| 墨脱县|