Spring 3 控制器 - 通过流程维护模型
我确信有某种方法可以完成我在这里想要的事情,但我无法在文档中找到它
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping(value = "/test")
public class TestController {
@RequestMapping(value = "/one")
public String one(Model m) {
System.out.println("one: m = " + m);
m.addAttribute("one", "valueone");
return "redirect:two";
}
@RequestMapping(value = "/two")
public String two(Model m) {
System.out.println("two: m = " + m);
return "redirect:three";
}
@RequestMapping(value = "/three")
public String three(Model m) {
System.out.println("three: m = " + m);
return "redirect:one/two/three";
}
@RequestMapping(value = "/one/two/three")
public String dest(Model m) {
System.out.println("one/two/three: m = " + m);
return "test";
}
}
我在这里期望的是看到模型属性“one”的值为“valueone” " 应该出现在方法调用 Two()、Three() 和 dest() 中,但它的缺失非常明显。我将如何使这项工作按预期进行?
I'm sure there is some way to accomplish what I'd like here, but I haven't been able to find it in the documentation
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping(value = "/test")
public class TestController {
@RequestMapping(value = "/one")
public String one(Model m) {
System.out.println("one: m = " + m);
m.addAttribute("one", "valueone");
return "redirect:two";
}
@RequestMapping(value = "/two")
public String two(Model m) {
System.out.println("two: m = " + m);
return "redirect:three";
}
@RequestMapping(value = "/three")
public String three(Model m) {
System.out.println("three: m = " + m);
return "redirect:one/two/three";
}
@RequestMapping(value = "/one/two/three")
public String dest(Model m) {
System.out.println("one/two/three: m = " + m);
return "test";
}
}
What I would expect here is to see that the model attribute "one" with value of "valueone" should be present in the method calls two(), three() and dest(), however it is quite conspicuous by it's absence. How would I make this work as expected?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在控制器上使用 @SessionAttributes 注释,然后使用 SessionStatus 来告诉框架您何时完成该属性。
请参阅 http ://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/web/bind/annotation/SessionAttributes.html
You need to use the @SessionAttributes annotation on the controller, then use a SessionStatus to tell the framework when you are done with the attribute.
See http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/web/bind/annotation/SessionAttributes.html