icemoff
icemoff
2012-07-05 16:00

spring3 MVC @controller 对应servlet 相应功能实现不出来

  • spring
  • 企业应用

在servlet 中,想在 doget()或者doPost()前后可以做些处理,servlet中代码如下:
[code="java"]public class BaseServlet extends HttpServlet {

    // 在service 前建立 ThreadLocal 缓存 ,service 完成后释放
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {


    ThreadLocal user = null;
    try{
    user = new ThreadLocal();
    super.service(request, response);
    }finally{
    user.remove();
    }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
    process(req,resp);
    }      

}
[/code]
在spring3 mvc中无法实现类似功能,我应该也要打到它的service()入口和出口的注解才可以做这样的处理,但苦于我实在找不到相应的资料,我现在的spring3 mvc代码如下:
[code="java"]@Controller
@RequestMapping("/user")
public class UserController{
@Resource
private UserService service;

    @RequestMapping("/list")
    private String list(Map modelt){
        PageModel pm = service.queryUser();
        model.put("pm", pm);
        return "user/list";
    }

}[/code]

要怎样才能实现上面servlet的功能

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答