struts2的结果类型中有一种类型为json,它的作用是显示json文件,它通过action中getter方法得到数据作为结果显示出来后,由javascript接收。结果显示形式为:[{xxxx,xxxx,xxxx},{xxx,xxx}]
Json为了加载一个类,由于牵涉到的类太多,使Json文件变得非常臃肿。大家请看:
[{"addtime":"2010-10-11T17:05:55","bid":2,"description":"dsfdsfs","name":"中级班","student":[{"addTime":"2010-09-22T15:55:16","address":{"fid":"19","grops":"shi","id":236,"name":"深圳市","treecode":"4403"},"banji":null,"bianhao":null,"grade":[{"id":"1","mark":89,"stu":null,"sub":{"sid":1,"subName":"语文"}}],"line":"sdfdsfsf","major":"JavaEE","person":"222222222222222222","realname":"张三","sex":"男","uid":16,"writer":"管理员"}]},{"addtime":"2010-10-11T17:05:51","bid":1,"description":"dsfdsf","name":"高级班","student":[{"addTime":"2010-09-29T14:17:50","address":{"fid":"1","grops":"shi","id":35,"name":"市辖区","treecode":"1101"},"banji":null,"bianhao":null,"grade":[{"id":"2","mark":87,"stu":null,"sub":{"sid":1,"subName":"语文"}}],"line":"东城区南池子大街","major":"ASP","person":"465465464646546546","realname":"李四","sex":"男","uid":24,"writer":"管理员"},{"addTime":"2010-09-29T14:23:08","address":{"fid":"2","grops":"shi","id":37,"name":"市辖区","treecode":"1201"},"banji":null,"bianhao":null,"grade":[],"line":"sdfdsfsdfdsf","major":"JavaEE","person":"899989898989898989","realname":"高峰","sex":"女","uid":25,"writer":"管理员"}]},{"addtime":"2010-10-11T15:18:00","bid":4,"description":"dsfsdf","name":"English","student":[{"addTime":"2010-10-11T15:19:59","address":{"fid":"6","grops":"shi","id":73,"name":"沈阳市","treecode":"2101"},"banji":null,"bianhao":null,"grade":[],"line":"sdfgdg","major":"dfgdfgdfg","person":"432423423432423423","realname":"麻子","sex":"女","uid":29,"writer":"管理员"},{"addTime":"2010-10-11T16:44:07","address":{"fid":"22","grops":"shi","id":272,"name":"市辖区","treecode":"5001"},"banji":null,"bianhao":"1286786647828","grade":[{"id":"402881992ba94299012ba9475dbe0004","mark":92,"stu":null,"sub":{"sid":1,"subName":"语文"}},{"id":"402881992ba94299012ba9448de50002","mark":99,"stu":null,"sub":{"sid":2,"subName":"高等数学"}},{"id":"402881992ba94299012ba9452c280003","mark":86,"stu":null,"sub":{"sid":3,"subName":"大学英语"}},{"id":"402881992ba973cf012ba974cf2a0001","mark":69,"stu":null,"sub":{"sid":5,"subName":"大学物理"}},{"id":"402881992ba973cf012ba9754eda0002","mark":99,"stu":null,"sub":{"sid":6,"subName":"理论力学"}}],"line":"fdgfdg","major":"javaEE","person":"143242432422222222","realname":"诸葛亮","sex":"男","uid":35,"writer":"管理员"}]},{"addtime":"2010-10-11T15:18:06","bid":5,"description":"fsdfsf","name":"chinese","student":[{"addTime":"2010-10-11T15:20:18","address":{"fid":"7","grops":"shi","id":87,"name":"长春市","treecode":"2201"},"banji":null,"bianhao":null,"grade":[],"line":"sdfsdf","major":"dsfdgd","person":"423324234234234234","realname":"王五","sex":"男","uid":30,"writer":"管理员"},{"addTime":"2010-10-11T15:22:04","address":{"fid":"10","grops":"shi","id":111,"name":"南京市","treecode":"3201"},"banji":null,"bianhao":null,"grade":[],"line":"dsfdsfds","major":"Asp.net","person":"321313123131231231","realname":"关羽","sex":"男","uid":33,"writer":"管理员"},{"addTime":"2010-10-11T15:22:30","address":{"fid":"9","grops":"shi","id":109,"name":"市辖区","treecode":"3101"},"banji":null,"bianhao":null,"grade":[{"id":"402881992ba94299012ba948a9e50005","mark":69,"stu":null,"sub":{"sid":5,"subName":"大学物理"}},{"id":"402881992ba94299012ba94ba0ee0006","mark":85,"stu":null,"sub":{"sid":1,"subName":"语文"}},{"id":"402881992ba94299012ba94efc4e0007","mark":84,"stu":null,"sub":{"sid":2,"subName":"高等数学"}},{"id":"402881992ba94299012ba94f267b0008","mark":63,"stu":null,"sub":{"sid":3,"subName":"大学英语"}},{"id":"402881992ba94299012ba94f4cee0009","mark":96,"stu":null,"sub":{"sid":4,"subName":"体育"}},{"id":"402881992ba94299012ba94f8f85000a","mark":95,"stu":null,"sub":{"sid":6,"subName":"思想概论"}}],"line":"fdsfd","major":"asp","person":"123123131323132132","realname":"张飞","sex":"女","uid":34,"writer":"管理员"}]},{"addtime":"2010-10-11T15:18:19","bid":6,"description":"sdfsdfsdfsd","name":"japanese","student":[{"addTime":"2010-10-11T15:20:48","address":{"fid":"18","grops":"shi","id":220,"name":"长沙市","treecode":"4301"},"banji":null,"bianhao":null,"grade":[{"id":"402881992ba951fb012ba95317740001","mark":69,"stu":null,"sub":{"sid":1,"subName":"语文"}},{"id":"402881992ba951fb012ba95354da0002","mark":97,"stu":null,"sub":{"sid":2,"subName":"高等数学"}},{"id":"402881992ba951fb012ba95376f90003","mark":98,"stu":null,"sub":{"sid":4,"subName":"体育"}},{"id":"402881992ba951fb012ba9539e470004","mark":91,"stu":null,"sub":{"sid":5,"subName":"大学物理"}},{"id":"402881992ba951fb012ba953cbcf0005","mark":85,"stu":null,"sub":{"sid":6,"subName":"思想概论"}}],"line":"dsfdsf","major":"java","person":"433243243242342343","realname":"李力","sex":"男","uid":31,"writer":"管理员"},{"addTime":"2010-10-11T16:44:41","address":{"fid":"3","grops":"shi","id":42,"name":"邯郸市","treecode":"1304"},"banji":null,"bianhao":"1286786681531","grade":[{"id":"402881992ba951fb012ba95ec300000a","mark":33,"stu":null,"sub":{"sid":1,"subName":"语文"}},{"id":"402881992ba951fb012ba95f9535000b","mark":69,"stu":null,"sub":{"sid":6,"subName":"思想概论"}}],"line":"dsfsfds","major":"asp.net","person":"142132131231321321","realname":"赵云","sex":"女","uid":36,"writer":null}]},{"addtime":"2010-10-11T15:18:29","bid":7,"description":"fdfsdf","name":"france","student":[{"addTime":"2010-10-11T15:21:33","address":{"fid":"6","grops":"shi","id":73,"name":"沈阳市","treecode":"2101"},"banji":null,"bianhao":null,"grade":[{"id":"402881992ba951fb012ba959d6af0006","mark":74,"stu":null,"sub":{"sid":2,"subName":"高等数学"}},{"id":"402881992ba951fb012ba95a327b0007","mark":89,"stu":null,"sub":{"sid":4,"subName":"体育"}},{"id":"402881992ba951fb012ba95a78db0008","mark":94,"stu":null,"sub":{"sid":6,"subName":"思想概论"}},{"id":"402881992ba951fb012ba95ae2e00009","mark":90,"stu":null,"sub":{"sid":5,"subName":"大学物理"}}],"line":"士大夫","major":"php","person":"321323131231312312","realname":"刘备","sex":"男","uid":32,"writer":"管理员"}]}]
暂时还找不到更好的方法给Json文件瘦身。但可以使用后台的力量将得到的list结果重新组合,具体办法就是遍历list结果,将不想要牵涉到的类设置为null,就不会自动加载了。