Which is better, return “ModelAndView” or “String” on spring3 controller

前端 未结 2 904
梦如初夏
梦如初夏 2020-11-28 18:32

The way of return ModelAndView

@RequestMapping(value = \"/list\", method = RequestMethod.GET)
public ModelAndView list(
    @UserAuth UserAuth user, 
    Mod         


        
相关标签:
2条回答
  • 2020-11-28 19:03

    I would like to add me 2 cents also. Second approach is more towards convention oriented i.e developer does explicitly mention what is his view but its implicit that return string is view name. So less coding,readable and standard. Much better than older way with ModelAndView

    0 讨论(0)
  • 2020-11-28 19:16

    There is no better way. Both are perfectly valid. Which one you choose to use depends which one suits your application better - Spring allows you to do it either way.

    Historically, the two approaches come from different versions of Spring. The ModelAndView approach was the primary way of returning both model and view information from a controller in pre-Spring 2.0. Now you can combine the Model parameter and the String return value, but the old approach is still valid.

    0 讨论(0)
提交回复
热议问题