简体   繁体   中英

angularjs and Spring MVC framework

I having trouble dealing with angularjs .

My code is like this:

$routeProvider

.when('/chart/pie',{
    templateUrl : 'chart/pie'
})

ChartController

public ModelAndView getChart(){
   ModelAndview mv = new ModelAndView();

   mv.setView("chart");

   mv.addObject("user", User);

   return mv;
}

chart.html

result : {{user}}

I would guessed I received [ result : {'name': 'haha', 'age' : '17'}] but result was: [result : {{user}} ]

How can I get the preferred result?

You need to return the User (not the model and view object), and need to add the ReponseBody annotation

@ResponseBody
public User getChart(){
    User user = ....
    return user;
}

Hint: from the Spring point of view, this problem has nothing to to with AngularJs, but sending a JSON response. So if you have more problems, that search for Spring and Json (a simple example can be found here ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM