嗨,我是棱角分明的春天。我正在尝试创建一个小例子,我从服务器接收用户数据并将其显示在网页上。我已成功建立连接但我无法打印收到的数据。附上的是代码。
网页代码:
<body>
<div ng-app="MyApp" ng-controller="MyCtrl">
<table>
<tr ng-repeat="user in data">
<td>{{user.name}}</td>
</tr>
</table>
</div>
<script>
var app=angular.module("MyApp",[]);
app.controller("MyCtrl",function($scope,$http){
$scope.data=[];
$http.get("/loginUser").then(function(response){
$scope.data=response
},function(){
})
});
</script>
</body>
控制器代码:
@Controller
public class MainController {
@RequestMapping(value="/loginUser",method=RequestMethod.GET)
public ResponseEntity<List<User>> getLoginInfo(){
String loginInfo="Controller hit";
System.out.println(loginInfo);
List<User> users=new ArrayList<User>();
users.add(new User("Jayant"));
System.out.println(users.size());
return new ResponseEntity<List<User>>(users, HttpStatus.OK);
}
}
用户类:
public class User {
private String name;
public User(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
答案 0 :(得分:0)
试试这个
$http.get("/loginUser").then(function(response){
$scope.data=response.data;
而不是响应使用response.data