首页 > 其他分享 >spring boot——请求与参数校验——spring-mvc——转发——forward

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

时间:2023-01-15 21:23:18浏览次数:43  
标签:RequestMapping spring boot springframework mvc testDispatcher org import public

 

 

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

相关文章