我有一个Spring MVC(3)控制器,我尝试放入批注,但是我的代码概述失败了
@Controller
public class SpringController {
@RequestMapping("/welcome")
public String myHandler(@RequestParam("id") String id) {
//My RequestParm is able to do the job of request.getParameter("id")
HttpSession session = request.getSession();
session.setAttribute("name","Mike") ;
return "myFirstJsp";
}
@RequestMapping("/process")
public String processHandler(@RequestParam("processId") String processId) {
//do stuff
String someName = session.getAttribute("name");
return "result";
}
}
仅仅为了会话对象,我必须声明HttpServletRequest和HttpSession。
无论如何,我们可以使用@nnotations解决方案。
谢谢!
最佳答案
如果没有,请查看SessionAttributes上的this documentation,以了解它是否适用于您。