为了账号安全,请及时绑定邮箱和手机立即绑定

使用了@RequiresRoles如果没有该角色抛出异常前端怎么处理

某个方法使用了@RequiresRoles注解,就代表有该角色才能访问,但是如果没有该角色去访问就抛出了异常,前端页面怎么捕获这个异常告知当前用户不具有该链接访问权呢


正在回答

2 回答

如果用了SpringMVC的话,设置的shiro的跳转貌似是没用的,这时候要在springMVC 里面配置,捕获异常并跳转:

<!-- 捕获无权限的异常进行跳转 -->
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
		<property name="exceptionMappings">				
		<props>						
        		<prop key="org.apache.shiro.authz.UnauthorizedException">
        			/unauthorized	
        		</prop>	
		
		</props>		
		</property>
</bean>

在controller中写一个方法,映射路径:

@RequestMapping("/unauthorized")
	public String unauthorized() {
			return "/403.html";
	}



0 回复 有任何疑惑可以回复我~
#1

小太阳和小月亮 提问者

谢谢你
2018-09-30 回复 有任何疑惑可以回复我~

多谢分享

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

使用了@RequiresRoles如果没有该角色抛出异常前端怎么处理

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信