0

I called the getUser in my app angularJS with Restangular service

Controller.java:

@RequestMapping("/user")
    public List<User> getUser(@ModelAttribute User user){
        List<User> list = new ArrayList<User>();
        list.add(user);
        return list;
    }

and in the angularJs :

var listUser= Restangular.all('path/user'); 
    var getMutafeUtente = function(){

        return listUser.getList().$object;
    }

runing the app i could enter to the getUser method and my user is setted perfectly in the list.

But arriving in angular with an empty list.

I tried with other method that uses the same logic and worked.

The only difference is that in getUser method there is the @ModelAttribute.

How can i pass attribut in session to AngularJs controller and then to my html page?

Vladyslav
  • 2,018
  • 4
  • 18
  • 44
selma
  • 77
  • 2
  • 12

1 Answers1

0

@ModelAttribute is used for Spring MVC (What is @ModelAttribute in Spring MVC?) You don't need that for communicating with AngularJS through REST

 public List<User> getUser(@RequestBody User user){
Alexander
  • 3,019
  • 1
  • 20
  • 24
  • and if the user is an object in session getted from another controller. How can i pass it to the controller that interface with angularJs? – selma Sep 21 '17 at 13:34
  • i got as response a non elaborated data:[{"user_id":"userID","name":"name","surname":"surname","email":"NULL"}] – selma Sep 21 '17 at 14:28
  • maybe because that restangular doesn't accept null value in JSon response: https://github.com/mgonto/restangular/issues/1257 – selma Sep 21 '17 at 14:33