Droga powrotna ModelAndViewKtóry jest lepszy, zwrot "ModelAndView" lub "String" na kontrolerze spring3
@RequestMapping(value = "/list", method = RequestMethod.GET)
public ModelAndView list(
@UserAuth UserAuth user,
ModelAndView mav) {
if (!user.isAuthenticated()) {
mav.setViewName("redirect:http://www.test.com/login.jsp");
return mav;
}
mav.setViewName("list");
mav.addObject("articles", listService.getLists());
return mav;
}
Sposób powrotnej String
@RequestMapping(value = "/list", method = RequestMethod.GET)
public String list(
@UserAuth UserAuth user,
Model model) {
if (!user.isAuthenticated()) {
return "redirect:http://www.test.com/login.jsp";
}
model.addAttribute("articles", listService.getLists());
return "list";
}
Działają one same. który jest lepszy sposób? i jaka jest różnica?
Dlatego podejście String jest nowe. – akshayb
@skaffman Czy możesz wyjaśnić, czy są jakieś różnice w sposobie, w jaki przetwarza się Spring, jak przedrostek contextpath itp. – Keerthivasan
proszę spojrzeć (http://stackoverflow.com/questions/37410839/spring-mvc-controller-working-but-not -popraszanie-podanej-adresu-url-it-is/37412537 # 37412537). podczas korzystania z ModelAndView mam ten problem –