4

Spring2.5 では、コントローラーを次のように記述します。

@Controller
public class HelloWorldController{

 @RequestMapping(value="/welcome",method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request,
    HttpServletResponse response) throws Exception {

    ModelAndView model = new ModelAndView("hello");
    model.addObject("msg", "hello world");

    return model;
}

}

春 3.1:

@RequestMapping(value="/welcome",method = RequestMethod.GET)
public String printWelcomeString(ModelMap model) {

    model.addAttribute("message", "hello world);
    return "hello";

}

printwelcomeString() 関数は、ModelAndView ではなく文字列を返します。

誰もそれをも​​っと説明できますか?どのように機能しますか?hello.jsp がモデルを表示する方法を教えてください。ありがとう :)

4

1 に答える 1

3

Spring 3.5 はまだリリースされていません。Spring 3.1 を意味していることを願っています。

return ModelAndViewSpring 2.0 で使用された古いスタイルのコード記述です。spring 3.0 add later では、ModelAndView または nameView の両方を返すことができます。

Spring MVC の一部の高度な機能が正しく動作しないため、常に String (ビュー名) を返すことをお勧めします。

例: Spring MVC 3.1 RedirectAttributes が機能しない

于 2012-04-26T06:42:07.353 に答える