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.ster开发者_开发技巧eotype.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?
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.
@Controller
@RequestMapping(value = "/test")
@SessionAttributes("one")
public class TestController {
// ...
@RequestMapping(value = "/one/two/three")
public String dest(Model m, SessionStatus status) {
System.out.println("one/two/three: m = " + m);
status.setComplete();
return "test";
}
}
See http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/web/bind/annotation/SessionAttributes.html
精彩评论