转发
package com.qf.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@Controller
public class ModelAndViewTest1 {
@RequestMapping("/m1/t1")
public String test(Model model){
model.addAttribute("msg","ModelAndViewTest1");
return "/WEB-INF/jsp/test.jsp";
}
}
重定向
package com.qf.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@Controller
public class ModelAndViewTest1 {
@RequestMapping("/m1/t1")
public String test(Model model){
model.addAttribute("msg","ModelAndViewTest1");
return "redirect:/index.jsp";
}
}
这是视图解析器的转发
package com.qf.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@Controller
public class ModelAndViewTest1 {
@RequestMapping("/m1/t1")
public String test(Model model){
model.addAttribute("msg","ModelAndViewTest1");
return "test";
}
}