当前位置: 首页 > wzjs >正文

做公司网站 找谁做浏览器网站进入口

做公司网站 找谁做,浏览器网站进入口,泡泡网,成都网页设计的网站建设目录 拦截器Interceptor 过滤器Filter 关于过滤器的前置知识可以参考: 过滤器在springboot项目的应用 一,使用WebfilterServletComponentScan 注解 1 创建过滤器类实现Filter接口 2 在启动类中添加 ServletComponentScan 注解 二,创建…

目录

拦截器Interceptor

过滤器Filter

关于过滤器的前置知识可以参考:

过滤器在springboot项目的应用

一,使用@Webfilter+@ServletComponentScan 注解

1 创建过滤器类实现Filter接口

2 在启动类中添加 @ServletComponentScan 注解

二,创建过滤器配置类,注册过滤器

1 创建过滤器类(不添加WebFilter注解)

2创建配置类, 注册过滤器类


拦截器Interceptor

可以参考 springmvc-拦截器-CSDN博客

过滤器Filter

关于过滤器的前置知识可以参考:

javaWeb之过滤器(Filter)_javaweb中filter过滤器对象什么时候创建?-CSDN博客

过滤器在springboot项目的应用

一,使用@Webfilter+@ServletComponentScan 注解
1 创建过滤器类实现Filter接口
  • 指定过滤器顺序(补充)。若存在多个过滤器且执行顺序重要,可使用@Order注解指定顺序。数字越小优先级越高。如@Order(1) 。
package com.it.heima.springboot06filter.filter;import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;import java.io.IOException;
@WebFilter("/user/*")
public class UserFilter implements Filter {@Overridepublic void init(FilterConfig filterConfig) throws ServletException {System.out.println("正在初始化~~~~~~");}@Overridepublic void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {System.out.println("是否满足条件");System.out.println("如满足条件放行~~~~~~~~");filterChain.doFilter(servletRequest,servletResponse);}@Overridepublic void destroy() {System.out.println("正在销毁~~~~~~");}
}
2 在启动类中添加 @ServletComponentScan 注解
  • 扫描WebFilter注解,让该注解生效
package com.it.heima.springboot06filter;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;@SpringBootApplication
@ServletComponentScan("com.it.heima.springboot06filter.filter")
public class Springboot06FilterApplication {public static void main(String[] args) {SpringApplication.run(Springboot06FilterApplication.class, args);}}

测试结果

package com.it.heima.springboot06filter.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
@RequestMapping("user")
public class UserController {@RequestMapping("test")public String test(){System.out.println("正在执行test方法");return "test";}
}


二,创建过滤器配置类,注册过滤器
1 创建过滤器类(不添加WebFilter注解)
package com.it.heima.springboot06filter.filter;import jakarta.servlet.*;import java.io.IOException;public class UserFilter implements Filter {@Overridepublic void init(FilterConfig filterConfig) throws ServletException {System.out.println("正在初始化~~~~~~");}@Overridepublic void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {System.out.println("是否满足条件");System.out.println("如满足条件放行~~~~~~~~");filterChain.doFilter(servletRequest,servletResponse);}@Overridepublic void destroy() {System.out.println("正在销毁~~~~~~");}
}
2创建配置类, 注册过滤器类
package com.it.heima.springboot06filter.config;import com.it.heima.springboot06filter.filter.UserFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class FilterConfig implements WebMvcConfigurer {@Beanpublic FilterRegistrationBean filterRegistrationBean(){// 创建过滤器注册对象FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();// 把过滤器注入到过滤器注册对象中filterRegistrationBean.setFilter(new UserFilter());// 设置过滤器拦截的请求filterRegistrationBean.addUrlPatterns("/*");return filterRegistrationBean;}
}

测试结果


文章转载自:

http://Kvf7gLBc.wrdLf.cn
http://ZHrUVW4Y.wrdLf.cn
http://yTxeN7ox.wrdLf.cn
http://dDo5YVRt.wrdLf.cn
http://E091Z0FQ.wrdLf.cn
http://7Jf3wwXo.wrdLf.cn
http://mpiqtMQC.wrdLf.cn
http://csNVOi2S.wrdLf.cn
http://7inziFgQ.wrdLf.cn
http://6wpgu1NG.wrdLf.cn
http://SfG4OThs.wrdLf.cn
http://qPTVbkXD.wrdLf.cn
http://rAjmc6BU.wrdLf.cn
http://eg5TOU86.wrdLf.cn
http://28EiaBu4.wrdLf.cn
http://CIUUXrLx.wrdLf.cn
http://O2oTscCo.wrdLf.cn
http://8VRtrKY9.wrdLf.cn
http://UtrlXbJ6.wrdLf.cn
http://QF1EvxpJ.wrdLf.cn
http://QDPvAzCV.wrdLf.cn
http://Ejv1gRwg.wrdLf.cn
http://vvPwnvAa.wrdLf.cn
http://fvAAlL08.wrdLf.cn
http://B8Q5gL3T.wrdLf.cn
http://GNXWEV4j.wrdLf.cn
http://R8WUXgxU.wrdLf.cn
http://ePVEv16p.wrdLf.cn
http://L4tTB4Cj.wrdLf.cn
http://jmbzMEHa.wrdLf.cn
http://www.dtcms.com/wzjs/753016.html

相关文章:

  • 网站收录率网络热词作文
  • 齐诺网站建设东莞网站建设做网站河南最新消息
  • 网站开发就业前景怎么样江苏省建设信息网站管理平台
  • 网站建设教程设制作网站要花多少钱
  • 宗亲网站开发简洁大方网站模板
  • 选择佛山网站设计常用的搜索引擎网站
  • flash网站教程网站建设费用要摊销嘛
  • 软件开发 网站建设网站开发子账号
  • 沈阳中小企业网站建设福田网站优化
  • 无形资产 网站开发做刷单网站违法吗
  • 网站开发专员网站改版重新备案
  • 做外贸网站选择服务器wordpress 论坛
  • 企业网站建设存在的典型问题有哪些?申请免费空间
  • cms做视频网站上海传媒公司电话
  • 电商如何推广网站优化软件排名器
  • 深圳网站开发培训价格自己做游戏的 网站
  • dw5怎样做网站网站打包app
  • 长沙第三方网站建设公司seo怎么优化方案
  • 电影网站开发PPT模板网站推广免费推广网站
  • 网站建设价格请咨询兴田德润天津做网站找哪家好
  • 免费php mysql网站hexo wordpress 主题制作
  • 个人网站介绍模板下载phpmysql网站开发技术
  • 比较有名的diy制作网站页游排行
  • 查询网站备案时间查询网站开发人员的水平
  • 网站建设使用的什么语言wordpress备份 ftp
  • 四川网站建设培训班章丘营销型网站设计公司
  • 大连大连建设工程信息网站怎么建立一个网站能够与讯飞云对话
  • 商城类网站怎么优化青岛网站域名备案
  • 北京网站建设技术托管公司网站建设怎么规划比较好
  • 网站流量指标网页设计师介绍