After receiving valid JSON Data through @RestController, I am wondering if my method of displaying it on an angular jsp is correct.
Spring Controller
@RequestMapping(value="/states",
method=RequestMethod.GET,produces= {"application/xml", "application/json"})
@ResponseStatus(HttpStatus.OK)
public Object getStates() throws Exception{
JSONObject obj = new JSONObject();
String result= dataManager.getStates();
obj.put("states", result);
return obj;
}
index.jsp
var app = angular.module('myApp', []);
function MyController($scope, $http){
$scope.getStateDataFromServer = function() {
$http({method: 'GET', url: 'http://localhost:8080/states'}).
success(function(data, status, headers, config) {
$scope.state = data;
}).
error(function(data, status, headers, config)
});
};
};
</script>
</head>
<body>
<div data-ng-app="myApp">
<div data-ng-controller="MyController">
<button data-ng-click="getStateDataFromServer()">Get State data from server</button>
<p>States : {{states}}</p>