Use ANGULARJS+STRUTS2 for data interaction and display on the front and back tables.
Struts.xml
The configuration file needs to be set extends= "Json-default" type= "JSON"
< Packagename= "Default"namespace="/"extends= "Json-default"> <Actionname= "Ajax"class= "com. Yiran583.action.ajacAction "> <resulttype= "JSON"/> </Action> </ Package>
Background code:
Set the appropriate Getter/setter method for properties that need to be passed to the foreground as JSON data
Privatelist<person> list =NewArraylist<person>(); Privateperson person ; @Override PublicString Execute ()throwsException {//TODO auto-generated Method Stub Person Person=NewPerson ("Yiran", 20); Person Person1=NewPerson ("jiao", 22); Person Person2=NewPerson ("Zhangsan", 18); List.add (Person1); List.add (Person2); List=jsonarray.fromobject (list); returnSUCCESS; } PublicList<person>getList () {returnlist; } Public voidSetlist (list<person>list) { This. List =list; }
Front desk:
Ng-repeat Loop Display
X.name,x.age is a property in a JSON object, respectively
$scope. name = A.list; Binds the result returned by the list object to name
<BodyNg-app> <spanID= "BTN"style= "cursor:pointer; font-size:20px">Action</span> <DivID= "Rdiv"Ng-controller= "MYCC">area to display data from<Ling-repeat= "x in Names">{{x.name+ "" +x.age}}</Li> </Div> <Scripttype= "Text/javascript"> functionMYCC ($scope, $http) {varURL= "ajax.action"; $http. Get (URL). Success (function(a) {$scope. Names=a.list; }); } </Script></Body>
Simple parsing JSON using ANGULARJS