这是我的RestController类
@RestController
@RequestMapping(value="/user")
public class Test {
@RequestMapping(value="/{userEmailId}",method=RequestMethod.GET)
public ModelAndView getUser(@PathVariable("userEmailId") String userEmailId){
//something goes here and get User class object
ModelAndView mav=new ModelAndView("showuser");
mav.addObject("user", user);//user is User class object
return mav;
}
}
我想使用Angular JS在showuser.jsp中显示这个用户对象我该怎么做?
答案 0 :(得分:0)
下面是假设您的用户对象具有名字和姓氏的示例示例:
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.min.js"></script>
</head>
<div ng-app="myApp" ng-controller="userController">
<form action="demo_form.html">
First name: <input type="text" name="fname" ng-model="fname"><br>
Last name: <input type="text" name="lname" ng-model="lname"><br>
</form>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('userController', function($scope, $http) {
$http({
method : "GET",
url : "/user/xyz@a.com"
}).then(function mySucces(response) {
$scope.fname = response.fname;
$scope.lname = response.lname;
}, function myError(response) {
//handling error
});
});
</script>