在数据库中拥有菜单表与用户权限表的情况下,页面上登录账号进去只能看到用户权限表中所存在的菜单,但由于不想每个接口都写权限审查,所以写了一个基于拦截器的权限判断来审查,防止用户在不经过页面操作而是直接通过url跳转到不在自己权限内的菜单中。
数据表:user表(若分角色组的需要另外一个角色表,这里是按账号区分的,所以直接把权限字段rights写在user表中)
menu表(菜单表,我这里设计的字段有menu_id,menu_name,menu_url,parent_id,menu_order,menu_icon, menu_type,menu_state)
拦截器代码:
<!-- 权限访问拦截 -->
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/**/*.do"/>
<bean class="com.mxr.interceptor.JurisdictionInterceptor"/>
</mvc:interceptor>
</mvc:interceptors>
拦截所有.do的url访问路径。
com.mxr.interceptor.JurisdictionInterceptor类:
public class JurisdictionInterceptor implements HandlerInterceptor {
private s