afunms

          My Software,My Dream—Forge a more perfect NMS product.

          Dynamic Bean

               學(xué)習(xí)Struts的過程中認識了DynaBean,一時不理解何為動態(tài)Bean。看了以下的例子,
          就很容易明白了。 

           

          import java.util.Date;

          import org.apache.commons.beanutils.BasicDynaClass;

          import org.apache.commons.beanutils.DynaBean;

          import org.apache.commons.beanutils.DynaClass;

          import org.apache.commons.beanutils.DynaProperty;

          public class TestService {

          public static void main(String[] hey) throws Exception{

          DynaProperty[] pro = new DynaProperty[]{//準備一個屬性,動態(tài)定義類依靠這些屬性來決定類的構(gòu)成。

          new DynaProperty("title", String.class),

          new DynaProperty("content", String.class),

          new DynaProperty("createdTime", Date.class),

          new DynaProperty("id", Integer.class),

          };

          DynaClass articleClass = new BasicDynaClass("Article",null,pro);//定義了一個類

          DynaBean article = articleClass.newInstance();//聲明了一個ArticleClass的對象

          article.set("title","this is a test");//對該對象進行操作

          article.set("content","oh my god");

          article.set("createdTime",new Date());

          article.set("id",new Integer(1));

          System.out.println(article.get("title"));

          System.out.println(article.get("content"));

          System.out.println(article.get("createdTime"));

          System.out.println(article.get("id"));

          }

          }

          posted on 2007-10-09 20:28 afunms 閱讀(706) 評論(0)  編輯  收藏


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


          網(wǎng)站導(dǎo)航:
           

          My Links

          News

          留言簿(18)

          隨筆檔案

          相冊

          搜索

          最新評論

          閱讀排行榜

          主站蜘蛛池模板: 黔西县| 龙岩市| 黑河市| 昂仁县| 南华县| 宣威市| 武城县| 邵东县| 柳江县| 江源县| 南投市| 青州市| 海兴县| 昔阳县| 夹江县| 呼图壁县| 漠河县| 防城港市| 田阳县| 麻城市| 宾川县| 江西省| 梨树县| 宜兰县| 林口县| 安康市| 辽宁省| 宁强县| 天柱县| 绥宁县| 台北县| 桂东县| 新宾| 鄱阳县| 获嘉县| 离岛区| 潍坊市| 新安县| 翁源县| 金秀| 竹北市|