使用angularjs ng模型绑定spring modelAndView对象值

时间:2018-04-13 03:23:11

标签: java angularjs spring-mvc

将modelObject与angularjs范围变量绑定的最佳方法是什么。 我试过如下

//controller
public ModelAndView getUsers(){
   ModelAndView mav = new ModelAndView();
   mav.addObejct("username","somename");
   mav.setViewName("users");
  return mav;
}

//jsp
<input ng-init="name='${username}'">
 {{name}}
//output
somename

用于任何其他对象

   //controller
public ModelAndView getUsers(){
   ModelAndView mav = new ModelAndView();
    List<String> username = new ArrayList();
    username.add("steve");
    username.add("mark");
    username.add("james");
   mav.addObejct("usernames",username);
   mav.setViewName("users");
  return mav;
}

//jsp
<input ng-init="name='${username}'">
 {{name}}
//output
[steve,james,mark]// the way looking like array but it is string format

谢谢你。

0 个答案:

没有答案