配置啟動服務器就加載SpringMVC

<load-on-startup>1</load-on-startup>
請求轉發
- 修改
MyFirstController
- 如果你沒有需要返回給前端頁面的數據可以直接返回一個字符串如下:

/**
* @author: BNTang
**/
@Controller
public class MyFirstController {
@RequestMapping("/second")
public String forwarding() {
return "/first";
}
}
- 返回一個字符串,其實內部做的還是轉發,直接轉發到某一個頁面當中
- 啟動項目發送請求即可進行驗證,同之前的例子
重定向

/**
* @author: BNTang
**/
@Controller
public class MyFirstController {
@RequestMapping("/first.action")
public ModelAndView show(){
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("name", "BNTang");
modelAndView.setViewName("redirect:/second.action");
return modelAndView;
}
@RequestMapping("/second")
public String forwarding(){
return "/first";
}
}