博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
关于springMVC重定向问题
阅读量:4230 次
发布时间:2019-05-26

本文共 1738 字,大约阅读时间需要 5 分钟。

@Controller
@RequestMapping(value = "/redirect")
public class Test {
 
    //进入路径/SpringMVCDemo/redirect/test1
    //重定向路径/SpringMVCDemo/redirect/index
    @RequestMapping("/test1")
    public ModelAndView test1(ModelAndView view) {
        view.setViewName("redirect:index");
        return view;
    }
 
    //进入路径/SpringMVCDemo/redirect/test2。
    //重定向路径/SpringMVCDemo/redirect/login
    @RequestMapping("/test2")
    public ModelAndView test2(ModelAndView view) {
        view.setViewName("redirect:login");
        return view;
    }
    //进入路径/SpringMVCDemo/redirect/test3。
    //重定向路径/SpringMVCDemo/index。
    @RequestMapping("/test3")
    public ModelAndView test3(ModelAndView view) {
        view.setViewName("redirect:/index");
        return view;
    }
 
    //进入路径/SpringMVCDemo/redirect/test4。
    //重定向路径/index。
    @RequestMapping("/test4")
    public ModelAndView test4(ModelAndView view) {
        view.setView(new RedirectView("/index", false));
        return view;
    }
 
    //进入路径/SpringMVCDemo/redirect/test5。
    //重定向路径/SpringMVCDemo/redirect/index。
    @RequestMapping("/test5")
    public ModelAndView test5(ModelAndView view) {
        view.setView(new RedirectView("index", false));
        return view;
    }
 
    //进入路径/SpringMVCDemo/redirect/test6/1。
    //重定向路径/SpringMVCDemo/index1?test=test。
    @RequestMapping("/test6/{id}")
    public ModelAndView test6(ModelAndView view, @PathVariable("id") int id) {
        view.setViewName("redirect:/index{id}");
        view.addObject("test", "test");
        return view;
    }
    
    //进入路径/SpringMVCDemo/redirect/test7/1
    //重定向路径/SpringMVCDemo/index{id}。
    @RequestMapping("/test7/{id}")
    public ModelAndView test7(ModelAndView view, @PathVariable("id") int id) {
        RedirectView redirectView = new RedirectView("/index{id}");
        redirectView.setExpandUriTemplateVariables(false);
        redirectView.setExposeModelAttributes(false);
        view.setView(redirectView);
        view.addObject("test", "test");
        return view;
    }
 
}

转载地址:http://xpjqi.baihongyu.com/

你可能感兴趣的文章
入门 | 一文概览深度学习中的激活函数
查看>>
一分钟整明白Tensorflow Extended
查看>>
人工智能再次参加高考:和作家比写作文,AI能打多少分?
查看>>
云创冬日紫金山踏雪游记
查看>>
西安思源学院电子信息工程学院院长张卫钢一行到访
查看>>
邀请函|欢迎参加2019云创大数据实验平台金融类/电子商务类/数学统计类院校各省总代理招募大会!...
查看>>
云创大数据的2018年!
查看>>
QNX简介
查看>>
MQTT协议基本介绍
查看>>
进程和线程是操作系统基本概念,了解一下
查看>>
SSL与TLS的区别以及介绍
查看>>
对象切割 - 常量引用传递
查看>>
北邮同学面经
查看>>
Effective C++条款16:成对使用new和delete时要采取相同形式
查看>>
sizeof与strlen
查看>>
一个递归+二分法的洗牌程序
查看>>
YUV格式注释
查看>>
一维、二维数组传参
查看>>
判断当前时间的下一秒是多少
查看>>
从文本文件中读取数据排序并输出到文本
查看>>