日期:2014-05-16  浏览次数:20343 次

Struts2处理json简介及注意事项
  1. action 中:??
  2. ????private??List<Admins>?entities;??
  3. ????private?Admins?admin;??
  4. ????public ?Admins?getAdmin()?{??
  5. ????????return ?admin;??
  6. ????}??
  7. ????public ?List<Admins>?getEntities()?{??
  8. ????????return ?entities;??
  9. ????}??
  10. ????public ?String?? execute (){??
  11. ????????AdminsService?asi?=?new?AdminsServiceImpl();??
  12. ????????entities?=?asi.getObjects(Admins.class);??
  13. ????????admin??=?(Admins)?asi.findObjectById(Admins.class,?1);??
  14. ????}??
  15. ??
  16. 配置文件中的内容为??
  17. 形式1:??
  18. <result?type="json" >???
  19. ????<param?name = "root" ></param>???
  20. </result>??
  21. 测试的结果为:??
  22. {"admin" :??
  23. {"address" : null , "cellPhone" : null , "email" : null , "id" :1, "password" : "ssssssss1" , "realName" : "sss1" , "role" : null , "sex" : null , "userName" : "redarmy1" },??
  24. "entities" :??
  25. [{"address" : null , "cellPhone" : null , "email" : null , "id" :1, "password" : "ssssssss1" , "realName" : "sss1" , "role" : null , "sex" : null , "userName" : "redarmy1" },??
  26. {"address" : null , "cellPhone" : null , "email" :<