Which return type use in spring mvc in @RequestMapping method?

前端 未结 3 1225
一整个雨季
一整个雨季 2020-12-09 05:36

I know in spring mvc in @Controller class in @RequestMapping method I can return

  1. String
  2. Model
  3. ModelAndView

I don\'t understa

3条回答
  •  被撕碎了的回忆
    2020-12-09 06:07

    Unless your return type is void or you annotate your method with @ResponseBody, Spring MVC will try to resolve a View to render the response.

    Therefore, you must somehow point the framework to a View instance or to the name of a view as String in your returned value (or rely on the implicit resolving and perhaps only return the Model); if you return a name (either as a mere String or embedded in a ModelAndView), that will then be passed to a configured ViewResolver to obtain an actual View instance.

    The ModelAndView container does hold a reference to a View or view name and also embeds the model to use.

提交回复
热议问题