2016年6月12日 星期日

Spring MVC中return ModelAndView以及return String


return ModelAndView經查詢是Spring 2.0之前版本所使用方式

如同上一個範例所寫


@RequestMapping("/hello_path")
public ModelAndView hello() {
  String message = "<h1>Hello World!</h1>";
  return new ModelAndView("hello", "message_el", message);
 }


改寫成retrun String則為


@RequestMapping("/hello_path")
public String hello(Model model){
 String message = "<h1>Hello World!</h1>";
 model.addAttribute("message_el", message);
 return "hello";
}

皆為相同作用
String是較新的做法

沒有留言:

張貼留言