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;
    }



}

 

 

 

posted @ 2023-01-15 21:14  小白龙白龙马  阅读(143)  评论(0)    收藏  举报