0

Here is my RestController Class

@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;
    }
}

I want to display this user object in showuser.jsp using Angular JS How can I do that?

Anil
  • 191
  • 1
  • 2
  • 11

1 Answers1

0

Below is sample example assuming your user object have firstname and lastname:

 <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> 
Sudhish K
  • 119
  • 5
  • Thanks for reply, I don't want to make request here, I have another page to request.I just want to display the user data. I wan to use it as view – Anil Aug 23 '16 at 11:27