当前位置: 首页 > news >正文 做律师推广的网站有哪些二维码活码生成器在线制作 news 2025/10/31 22:54:21 做律师推广的网站有哪些,二维码活码生成器在线制作,庆阳网红刘斌个人资料简介,企业网站建设信息管理平台目录 项目配置类 项目中配置的相关代码 spring Boot 拦截器相关知识 一、基于URL实现的拦截器#xff1a; 二、基于注解的拦截器 三、把拦截器添加到配置中#xff0c;相当于SpringMVC时的配置文件干的事儿#xff1a; 项目配置类 项目中配置的相关代码 首先定义项目认…目录 项目配置类 项目中配置的相关代码 spring Boot 拦截器相关知识 一、基于URL实现的拦截器 二、基于注解的拦截器 三、把拦截器添加到配置中相当于SpringMVC时的配置文件干的事儿 项目配置类 项目中配置的相关代码 首先定义项目认证授权拦截器 AuthorizationInterceptor 把这个类注册为 bean 使用的是 Bean注解 其次是重写 addInterceptors方法 将然后将注册的认证授权bean 添加到拦截器的链条当中设置是所有请求都要过拦截器出了static下面的静态资源不拦截 然后是重写 addResourceHandlers 这里是对项目的静态资源做定向解析addResourceHandlers是请求路径.addResourceLocations 是资源的路径 spring Boot 拦截器相关知识 其实spring boot拦截器的配置方式和springMVC差不多只有一些小的改变需要注意下就ok了。 下面主要介绍两种常用的拦截器 一、基于URL实现的拦截器 public class LoginInterceptor extends HandlerInterceptorAdapter{ Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { String path request.getServletPath(); if (path.matches(Const.NO_INTERCEPTOR_PATH)) { //不需要的拦截直接过 return true; } else { // 这写你拦截需要干的事儿比如取缓存SESSION权限判断等 System.out.println(); return true; } } } 关键代码path.matches(Const.NO_INTERCEPTOR_PATH 就是基于正则匹配的url。 public class Const { public static final String SUCCESS SUCCESS; public static final String ERROR ERROR; public static final String FIALL FIALL; /**********************对象和个体****************************/ public static final String SESSION_USER loginedAgent; // 用户对象 public static final String SESSION_LOGINID sessionLoginID; // 登录ID public static final String SESSION_USERID sessionUserID; // 当前用户对象ID编号 public static final String SESSION_USERNAME sessionUserName; // 当前用户对象ID编号 public static final Integer PAGE 10; // 默认分页数 public static final String SESSION_URL sessionUrl; // 被记录的url public static final String SESSION_SECURITY_CODE sessionVerifyCode; // 登录页验证码 // 时间 缓存时间 public static final int TIMEOUT 1800;// 秒 public static final String ON_LOGIN /logout.htm; public static final String LOGIN_OUT /toLogout; // 不验证URL anon不验证/authc受控制的 public static final String NO_INTERCEPTOR_PATH .*/((.css)|(.js)|(images)|(login)|(anon)).*; } 二、基于注解的拦截器 ①创建注解 /** * 在需要登录验证的Controller的方法上使用此注解 */ Target({ElementType.METHOD})// 可用在方法名上 Retention(RetentionPolicy.RUNTIME)// 运行时有效 public interface LoginRequired { } ②创建拦截器 public class AuthorityInterceptor extends HandlerInterceptorAdapter{ Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { // 如果不是映射到方法直接通过 if (!(handler instanceof HandlerMethod)) { return true; } // ①:START 方法注解级拦截器 HandlerMethod handlerMethod (HandlerMethod) handler; Method method handlerMethod.getMethod(); // 判断接口是否需要登录 LoginRequired methodmethodAnnotation method.getAnnotation(LoginRequired.class); // 有 LoginRequired 注解需要认证 if (methodAnnotation ! null) { // 这写你拦截需要干的事儿比如取缓存SESSION权限判断等 System.out.println(); return true; } return true; } } 三、把拦截器添加到配置中相当于SpringMVC时的配置文件干的事儿 /** * 和springmvc的webmvc拦截配置一样 * author BIANP */ Configuration public class WebConfigurer implements WebMvcConfigurer { Override public void addInterceptors(InterceptorRegistry registry) { // 拦截所有请求通过判断是否有 LoginRequired 注解 决定是否需要登录 registry.addInterceptor(LoginInterceptor()).addPathPatterns(/**); registry.addInterceptor(AuthorityInterceptor()).addPathPatterns(/**); } Bean public LoginInterceptor LoginInterceptor() { return new LoginInterceptor(); } Bean public AuthorityInterceptor AuthorityInterceptor() { return new AuthorityInterceptor(); } } 1、一定要加Configuration 这个注解在启动的时候在会被加载。 2、有一些教程是用的“WebMvcConfigurerAdapter”不过在spring5.0版本后这个类被丢弃了 WebMvcConfigurerAdapter 虽然还可以用但是看起来不好。 3、也有一些教程使用的WebMvcConfigurationSupport我使用后发现classpath:/META/resources/classpath:/resources/classpath:/static/classpath:/public/不生效。具体可以原因大家可以看下源码因为WebMvcAutoConfiguration上有个条件注解 ConditionalOnMissingBean(WebMvcConfigurationSupport.class) 所以还是建议使用WebMvcConfigurer 其实springMVC很多东西都可以搬到springboot中来使用只需要把配置文件的模式改成 对应Configuration 类就好了。 文章转载自: http://www.morning.lhgqc.cn.gov.cn.lhgqc.cn http://www.morning.xdnhw.cn.gov.cn.xdnhw.cn http://www.morning.pkrtz.cn.gov.cn.pkrtz.cn http://www.morning.fxkgp.cn.gov.cn.fxkgp.cn http://www.morning.yhywx.cn.gov.cn.yhywx.cn http://www.morning.ysnbq.cn.gov.cn.ysnbq.cn http://www.morning.ysjjr.cn.gov.cn.ysjjr.cn http://www.morning.wzknt.cn.gov.cn.wzknt.cn http://www.morning.mjzcp.cn.gov.cn.mjzcp.cn http://www.morning.jybj.cn.gov.cn.jybj.cn http://www.morning.yltnl.cn.gov.cn.yltnl.cn http://www.morning.nrpp.cn.gov.cn.nrpp.cn http://www.morning.ptqds.cn.gov.cn.ptqds.cn http://www.morning.ttvtv.cn.gov.cn.ttvtv.cn http://www.morning.dxrbp.cn.gov.cn.dxrbp.cn http://www.morning.znrgq.cn.gov.cn.znrgq.cn http://www.morning.nyhtf.cn.gov.cn.nyhtf.cn http://www.morning.mxmzl.cn.gov.cn.mxmzl.cn http://www.morning.ndxrm.cn.gov.cn.ndxrm.cn http://www.morning.ybshj.cn.gov.cn.ybshj.cn http://www.morning.kpxnz.cn.gov.cn.kpxnz.cn http://www.morning.pttrs.cn.gov.cn.pttrs.cn http://www.morning.gqjwz.cn.gov.cn.gqjwz.cn http://www.morning.cwznh.cn.gov.cn.cwznh.cn http://www.morning.jcyrs.cn.gov.cn.jcyrs.cn http://www.morning.rsnd.cn.gov.cn.rsnd.cn http://www.morning.mwkwg.cn.gov.cn.mwkwg.cn http://www.morning.tjkth.cn.gov.cn.tjkth.cn http://www.morning.kfbth.cn.gov.cn.kfbth.cn http://www.morning.bpmdn.cn.gov.cn.bpmdn.cn http://www.morning.hwsgk.cn.gov.cn.hwsgk.cn http://www.morning.xhqwm.cn.gov.cn.xhqwm.cn http://www.morning.mprpx.cn.gov.cn.mprpx.cn http://www.morning.lmyq.cn.gov.cn.lmyq.cn http://www.morning.cyjjp.cn.gov.cn.cyjjp.cn http://www.morning.fqklt.cn.gov.cn.fqklt.cn http://www.morning.djxnw.cn.gov.cn.djxnw.cn http://www.morning.qnpyz.cn.gov.cn.qnpyz.cn http://www.morning.cpktd.cn.gov.cn.cpktd.cn http://www.morning.bpmnj.cn.gov.cn.bpmnj.cn http://www.morning.rqqn.cn.gov.cn.rqqn.cn http://www.morning.hgfxg.cn.gov.cn.hgfxg.cn http://www.morning.kntbk.cn.gov.cn.kntbk.cn http://www.morning.lbfgq.cn.gov.cn.lbfgq.cn http://www.morning.wmfmj.cn.gov.cn.wmfmj.cn http://www.morning.tkcct.cn.gov.cn.tkcct.cn http://www.morning.ggnfy.cn.gov.cn.ggnfy.cn http://www.morning.nynyj.cn.gov.cn.nynyj.cn http://www.morning.jrplk.cn.gov.cn.jrplk.cn http://www.morning.smsjx.cn.gov.cn.smsjx.cn http://www.morning.kbkcl.cn.gov.cn.kbkcl.cn http://www.morning.xptkl.cn.gov.cn.xptkl.cn http://www.morning.rlsd.cn.gov.cn.rlsd.cn http://www.morning.ebpz.cn.gov.cn.ebpz.cn http://www.morning.ypdhl.cn.gov.cn.ypdhl.cn http://www.morning.rgxcd.cn.gov.cn.rgxcd.cn http://www.morning.lkpzx.cn.gov.cn.lkpzx.cn http://www.morning.jczjf.cn.gov.cn.jczjf.cn http://www.morning.bflwj.cn.gov.cn.bflwj.cn http://www.morning.synkr.cn.gov.cn.synkr.cn http://www.morning.hjssh.cn.gov.cn.hjssh.cn http://www.morning.hysqx.cn.gov.cn.hysqx.cn http://www.morning.prsxj.cn.gov.cn.prsxj.cn http://www.morning.xnqjs.cn.gov.cn.xnqjs.cn http://www.morning.rrcrs.cn.gov.cn.rrcrs.cn http://www.morning.gfhng.cn.gov.cn.gfhng.cn http://www.morning.nfzw.cn.gov.cn.nfzw.cn http://www.morning.kdnrc.cn.gov.cn.kdnrc.cn http://www.morning.zrnph.cn.gov.cn.zrnph.cn http://www.morning.tmrjb.cn.gov.cn.tmrjb.cn http://www.morning.rkfh.cn.gov.cn.rkfh.cn http://www.morning.mwrxz.cn.gov.cn.mwrxz.cn http://www.morning.fpngg.cn.gov.cn.fpngg.cn http://www.morning.bsplf.cn.gov.cn.bsplf.cn http://www.morning.hchrb.cn.gov.cn.hchrb.cn http://www.morning.fstesen.com.gov.cn.fstesen.com http://www.morning.lbpqk.cn.gov.cn.lbpqk.cn http://www.morning.zyytn.cn.gov.cn.zyytn.cn http://www.morning.xtlty.cn.gov.cn.xtlty.cn http://www.morning.pxtgf.cn.gov.cn.pxtgf.cn 查看全文 http://www.tj-hxxt.cn/news/266411.html 相关文章: 华强北手机网站建设wordpress访问许可 建设部网站退休注册人员营销型网站建设合同模板 优化网站专题宁波网站制作工具 济南shuncheng科技 网站建设自己做的网站 如何用ps做网站设计图wordpress打电话插件 自建免费网站哪个好网易博客搬家wordpress 免费的网站开发工具在线A视频做爰网站 做一个京东这样的网站需要多少钱浙江网站建设推广 湖南网站模板建站老干局网站建设方案 网站建设类的论文题目南通高端网站建设开发 网站建设 东阿阿胶网站点击量 哪里查询 德州网站建设哪家好有建设银行信用卡怎么登陆不了网站 长沙小升初有什么做试卷的网站零基础学做网站页 电子商务网站建设与维护论文外贸如何网络推广 澄海网站建设公司哈尔滨的网站建设公司 地方门户网站建设青海省建设厅网站执业 网站制作方案报价品牌创建策划方案 厦门市建设合同备案网站商城网站设计费用 烟台建设集团 招聘信息网站腾讯的网站是谁做的 梧州网站建设哪家好nas云存储做视频网站 网站顶部下拉广告代码顺德网站制作案例如何 单页面网站可以做自适应网站吗烟台app开发公司 网站seo优化方案设计php网站开发招聘 怎么挑选网站主机怎么对页面颜色进行设计 免费制作网站方案全屋定制报价明细表 ?a品定制网站开发网站支付端口 企业服务账号十堰seo排名公司 建设银行对账网站西双版纳傣族自治州景洪市 福建省城市建设厅网站沧州百度建设网站 毕设做网站难吗网名logo设计制作