后端配置拦截器的一个问题【问题】
- 前言
- 版权
- 后端配置拦截器的一个问题
- 问题
- 解决
- 最后
前言
2024-3-14 00:07:28
以下内容源自《【问题】》
仅供学习交流使用
版权
禁止其他平台发布时删除以下此话
本文首次发布于CSDN平台
作者是CSDN@日星月云
博客主页是https://jsss-1.blog.csdn.net
禁止其他平台发布时删除以上此话
后端配置拦截器的一个问题
问题
做毕设项目遇到一个问题
有下面几个权限
"/report/report", 增
"/report/delete", 删
"/report/update" 改
"/report/search" 查
"/admin/*" 管理员独立操作的路径
"/doctor/*" 医生独立操作的路径
"/family/*" 家属独立操作的路径
管理员
可以访问 "/admin/*"
以及增删改查 "/report/report" "/report/delete" "/report/update" "/report/search"
医生
可以访问 "/doctor/*"
以及增删改查 "/report/report" "/report/delete" "/report/update" "/report/search"
家属
可以访问 "/family/*"
以及查"/report/search"
这个怎么配置拦截器?
@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {@Overridepublic void addInterceptors(InterceptorRegistry registry) {registry.addInterceptor(loginCheckInterceptor).addPathPatterns("/**").excludePathPatterns("/user/login", "/user/register");registry.addInterceptor(adminInterceptor).addPathPatterns("/admin/*");registry.addInterceptor(doctorInterceptor).addPathPatterns("/doctor/*");registry.addInterceptor(familyInterceptor).addPathPatterns("/family/*");}
}
解决
2024-3-15 14:24:20
再建个拦截器,包含管理员和医生权限就可以了
package com.jsss.configuration;import com.jsss.controller.Interceptor.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {@Autowiredprivate LoginCheckInterceptor loginCheckInterceptor;@Autowiredprivate AdminInterceptor adminInterceptor;@Autowiredprivate AdminAndDoctorInterceptor adminAndDoctorInterceptor;@Autowiredprivate DoctorInterceptor doctorInterceptor;@Autowiredprivate FamilyInterceptor familyInterceptor;@Overridepublic void addInterceptors(InterceptorRegistry registry) {//登录拦截器配置registry.addInterceptor(loginCheckInterceptor).addPathPatterns("/**").excludePathPatterns("/user/login", "/user/register"/*,"/{path}/captcha"*/);// 管理员拦截器配置registry.addInterceptor(adminInterceptor).addPathPatterns("/admin/*");// 医生拦截器配置registry.addInterceptor(doctorInterceptor).addPathPatterns("/doctor/*");// 管理员和医生拦截器配置// 2.体检日历// 3.体检报告// 4.诊断意见// 6.消息提醒registry.addInterceptor(adminAndDoctorInterceptor).addPathPatterns("/calendar/calendar","/calendar/delete","/calendar/update","/calendar/captcha","/report/report","/report/delete","/report/update", "/report/captcha","/opinion/opinion","/opinion/delete","/opinion/update","/opinion/captcha","/remind/remind","/remind/delete","/remind/update","/remind/captcha");// 家属拦截器配置// 1.体检预约// 5.消息咨询registry.addInterceptor(familyInterceptor).addPathPatterns("/family/*","/appointment/appoint","/appointment/delete","/appointment/update","/appointment/captcha","/information/inform","/information/delete","/information/update","/information/captcha");}}
最后
2024-3-15 14:26:13
迎着日光月光星光,直面风霜雨霜雪霜。