spring boot——请求与参数校验——spring-mvc——转发——forward


package org.example.controller.requestparam; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @Controller public class RequestForwardingAndRedirectionController { // http://localhost:8080/hello @ResponseBody @RequestMapping("/helloTest001") public String hellotest001() { return "Hello World!____________china"; } // http://localhost:8080/testDispatcher @RequestMapping("/testDispatcher") public String testDispatcher() { return "forward:/helloTest001"; } }



package org.example.controller.requestparam; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; @Controller public class RequestForwardingAndRedirectionController { // http://localhost:8080/hello @ResponseBody @RequestMapping("/helloTest001") public String hellotest001() { return "Hello World!____________china"; } // http://localhost:8080/testDispatcher @RequestMapping("/testDispatcher") public String testDispatcher() { return "forward:/helloTest001"; } // http://localhost:8080/testDispatcher2 @RequestMapping("/testDispatcher2") public ModelAndView testDispatcher2() { ModelAndView modelAndView = new ModelAndView(); //设置逻辑视图名 modelAndView.setViewName("forward:/helloTest001"); return modelAndView; } }



浙公网安备 33010602011771号