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; } }
标签:RequestMapping,spring,boot,springframework,mvc,testDispatcher,org,import,public From: https://www.cnblogs.com/xiaobaibailongma/p/17054153.html