spring aop中获取request对象

应用场景是简单做个后台的权限管理,目前还没吃透shiro,并且时间不多。

用aop切入systemService中以do开头的方法,获取session中的用户Id,查看用户是否具有修改权限,如果没权限,就抛出异常,交给自定义的异常处理器去处理,转向提示页面

RequestAttributes ra = RequestContextHolder.getRequestAttributes();  

ServletRequestAttributes sra = (ServletRequestAttributes) ra;  

HttpServletRequest request = sra.getRequest();

如果context报空指针就在web.xml中添加

<listener>
 <listener-class>
         org.springframework.web.context.request.RequestContextListener
 </listener-class>
</listener>

 

猜你喜欢

转载自www.cnblogs.com/lvsunshine21/p/9093782.html
今日推荐