當前位置:
首頁 >
struts2注解json 配置文件json
發布時間:2025/3/20
22
豆豆
生活随笔
收集整理的這篇文章主要介紹了
struts2注解json 配置文件json
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
java提供了便捷的Json-lib ?類庫,能夠讓我們很方便的將 Array?/ JavaBean / Map 解析成 JSON 串,當然反之也是可以的。
struts2借助于json-lib類庫,?在開發過程中,很容易轉換獲得前端顯示需要的json數據。我們只需簡單配置即可,不需要關注具體轉換過程。
1.注解Action中寫法:
1 @ParentPackage("json-default") 2 public class TestAction extends BaseAction{ 3 4 @Action(value="/faq/queryjsonList",results=@Result(type="json",name="jsonlist",params={"includeProperties","noticeBills.*"})) 5 public String queryjsonList(){ 6 this.noticeBills= infoService.selectByTitleAndTypeForNormal(title, type);7 return "jsonlist";
8 }
9}
?
2.在配置文件中實現設置的寫法:
1、action中對應的方法public String findnoassociations(){List<NoticeBill> noticeBills = noticeBillService.findnoassociations();ActionContext.getContext().put("noticeBills", noticeBills);return "findnoassociationsSUCCESS";}
2、struts.xml中配置寫法
<package name="qp" extends="json-default"> <action name="noticebill_*" class="noticebillAction" method="{1}"><result name="findnoassociationsSUCCESS" type="json">
<param name="root">noticeBills</param><param name="includeProperties">\[\d+\]\.id,\[\d+\]\.delegater,\[\d+\]\.telephone,\[\d+\]\.pickaddress,\[\d+\]\.product,\[\d+\]\.pickdate</param></result> </action> </package>
以上兩種方式都可。
?
?
轉載于:https://www.cnblogs.com/youhun/p/3586109.html
總結
以上是生活随笔為你收集整理的struts2注解json 配置文件json的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python关键字参数
- 下一篇: checkbox 与文字对齐