Spring MVC简单重定向控制器示例

问题描述 投票:-1回答:1

嗨,我正在尝试比较各种框架的重定向方法。

我做了很多:

然而,我一直试图为Spring MVCJSF创建最简单的例子。

我想要的是一个或两个控制器,它们处理/ index和/ redirect url,其中/ index只链接到/ redirect,而/ redirect使用301重定向重定向回/ index。

我找到了this documentation,我只是没有持久性来弄清楚如何在Spring MVC中创建这个看似简单的例子。

谢谢!

jsf spring-mvc
1个回答
0
投票

只是因为我在JSF和SPring MVC中使用重定向:

JSF:

  <navigation-rule>
    <from-view-id>index.xhtml</from-view-id>
    <navigation-case>
        <from-action>#{actionController.actionSubmitted}</from-action>
        <from-outcome>success</from-outcome>
        <to-view-id>index.xhtml</to-view-id>
        <redirect />
    </navigation-case>
    </navigation-rule>  

Spring-MVC在POST / REdirect / GET设计模式中提交用户表单:

@RequestMapping(value="/index.html", method=RequestMethod.GET)
public ModelAndView index(){
    ModelAndView mv = new ModelAndView("index");
    User user = new User();
        mv.addObject("user", user);
    return mv;
}

 @RequestMapping(value="/signin.html",method = RequestMethod.POST)
 public ModelAndView submit(@Valid User user){
    ModelAndView mv = new ModelAndView("redirect:index.html"); 
    System.out.println(user.getFirstName());
    return mv;
 }

希望能帮助到你。

© www.soinside.com 2019 - 2024. All rights reserved.