Struts result param詳細設置

Xml代碼  收藏代碼

  1. <result type="json">  

  2.                 <!-- 這裏指定將被Struts2序列化的屬性,該屬性在action中必須有對應的getter方法 -->  

  3.                 <!-- 默認將會序列所有有返回值的getter方法的值,而無論該方法是否有對應屬性 -->  

  4.                 <param name="root">dataMap</param>  

  5.                 <!-- 指定是否序列化空的屬性 -->  

  6.                 <param name="excludeNullProperties">true</param>  

  7.                 <!-- 這裏指定將序列化dataMap中的那些屬性 -->  

  8.                 <param name="includeProperties">  

  9.                     userList.*  

  10.                 </param>  

  11.                 <!-- 這裏指定將要從dataMap中排除那些屬性,這些排除的屬性將不被序列化,一半不與上邊的參數配置同時出現 -->  

  12.                 <param name="excludeProperties">  

  13.                     SUCCESS  

  14.                 </param>  

  15. </result>  



Xml代碼  收藏代碼

  1. <!-- 新聞跳轉管理 -->  

  2.         <action  

  3.             name="news"  

  4.             class="newsAction">  

  5.             <result>/content/news/index.jsp</result>  

  6.             <result  

  7.                 name="update"  

  8.                 type="json" />  

  9.             <!--<result  

  10.                 name="detail">/content/news/detail.jsp</result>  

  11.             -->  

  12.             <result  

  13.                 name="detail"  

  14.                 type="json">  

  15.                 <param  

  16.                     name="includeProperties">name,list.*,feeds.*</param>  

  17.             </result>  

  18.         </action>  



Java代碼  收藏代碼

  1. private String name;  

  2.     private INewsService newsService;  

  3.     private List list;  

  4.     private WeiboFeeds feeds = new WeiboFeeds();  

  5.     private Map<String, Object> session;  

  6.   

  7.     public WeiboFeeds getFeeds() {  

  8.         return feeds;  

  9.     }  

  10.   

  11.     public void setFeeds(WeiboFeeds feeds) {  

  12.         this.feeds = feeds;  

  13.     }  

  14.   

  15.     public List getList() {  

  16.         return list;  

  17.     }  

  18.   

  19.     public void setList(List list) {  

  20.         this.list = list;  

  21.     }  

  22.   

  23.     public INewsService getNewsService() {  

  24.         return newsService;  

  25.     }  

  26.   

  27.     public void setNewsService(INewsService newsService) {  

  28.         this.newsService = newsService;  

  29.     }  

  30.   

  31.     public String getName() {  

  32.         return name;  

  33.     }  

  34.   

  35.     public void setName(String name) {  

  36.         this.name = name;  

  37.     }  



Js代碼  收藏代碼

  1. $("#subForm").click(function() {  

  2.                 var url = "news!retrieveById.action";  

  3.                 $.ajax({  

  4.                             url : url,  

  5.                             cache : false,  

  6.                             data : {  

  7.                                 "name" : "I love You!"  

  8.                             },  

  9.                             type : "POST",  

  10.                             datatype : "json",  

  11.                             success : function(data) {  

  12.                                 // alert(data.feeds.id);  

  13.                                 var result = "";  

  14.                                 $.each(data.list, function(index, value) {  

  15.                                             result += (index + "[==]" + value[index]);  

  16.                                         });  

  17.                                 result += "//////////////////////\r";  

  18.                                 $.each(data.list[1], function(index, value) {  

  19.                                             result += (index + "[==]" + value);  

  20.                                         });  

  21.                                 alert(result);  

  22.                             }  

  23.                         });  

  24.             });  



08764b10-e6d7-3523-9da4-51e445e24cb4.jpg

http://www.open-open.com/lib/view/open1325518231062.html  


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章