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:21 Wingel 閱讀(1300) 評論(0)  編輯  收藏

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


          網站導航:
           
          主站蜘蛛池模板: 阜南县| 万宁市| 黑水县| 信宜市| 宁城县| 施秉县| 马公市| 九江市| 太仓市| 阿坝| 酒泉市| 墨脱县| 东至县| 杭锦后旗| 寿光市| 绥化市| 大荔县| 依兰县| 香格里拉县| 莱阳市| 托克逊县| 修水县| 岑巩县| 阜新| 瑞安市| 英山县| 游戏| 迁安市| 高淳县| 枣庄市| 登封市| 青川县| 高台县| 青海省| 张掖市| 工布江达县| 宾川县| 綦江县| 鹤山市| 迁安市| 鹤峰县|