默认写法就是转发:return的字符串将对应的前端页面转发到要求的url上
配置了视图解析器的viewsresolver
@RequestMapping("/hello/{a}/{b}")
public String hello(@PathVariable int a, @PathVariable int b, Model model) {
model.addAttribute("haha", "结果:" + (a + b));
return "hello";
}
没有视图解析器的viewsresolver:需要把路径名字都加上
@RequestMapping("/hello/{a}/{b}")
public String hello(@PathVariable int a, @PathVariable int b, Model model) {
model.addAttribute("haha", "结果:" + (a + b));
return "/WEB-INF/jsp/hello,jsp";
}
写的清楚些:forward:转发
@RequestMapping("/hello/{a}/{b}")
public String hello(@PathVariable int a, @PathVariable int b, Model model) {
model.addAttribute("haha", "结果:" + (a + b));
return "forward:/hello,jsp";
}
重定向:redirect:重定向
@RequestMapping("/hello/{a}/{b}")
public String hello(@PathVariable int a, @PathVariable int b, Model model) {
model.addAttribute("haha", "结果:" + (a + b));
return "redirect:/hello.jsp";
}