当前位置: 首页 > 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://www.dtcms.com/wzjs/332312.html

相关文章:

  • dedecms 做网站站长工具综合查询ip
  • 网上外贸网站怎么做南宁网站关键词推广
  • 建设工程质量检测公司网站网站优化费用报价明细
  • 网站制作公司宁波哪家好搜索推广出价多少合适
  • 做门票售卖网站百度收录入口
  • 网站建设及优化百度关键词排名批量查询工具
  • 建设茶网站网站测试友情链接系统
  • 康定网站建设工作室关键词歌词完整版
  • 网站建设基本流程规范杭州疫情最新消息
  • 常州网站建设公司信息站外引流推广渠道
  • 做汽车微信广告视频网站有哪些网站安全检测工具
  • 佛山做网站永网北京最新疫情最新消息
  • 灵犀科技 高端网站建设百度搜索风云榜单
  • 今日油价92汽油郑州有没有厉害的seo顾问
  • 公司给别人做的网站违法的吗十大看免费行情的软件下载
  • 网站更改网页制作的软件有哪些
  • 个人可以做外贸的网站抓关键词的方法10条
  • 网站建设中搜索引擎的作用百度爱采购竞价推广
  • 驻马店网站制作太原seo管理
  • 邯山专业做网站站长工具seo综合查询网
  • 英迈思做的网站怎么样如何编写一个网站
  • 太原深圳建设工程信息网站百度域名
  • 西安做网站陕西必达电脑优化系统的软件哪个好
  • 接单子做网站关键词云图
  • 威海市住房和城乡建设局网站云优化
  • 莆田兼职做外贸网站网络推广公司北京
  • 电子商务网站建设知识点总结seocms
  • 室内设计学校大专seo对网店推广的作用
  • 专业的上海网站建设公司排名流量主广告点击自助平台
  • wordpress获取指定分类的图像描述网站seo搜索引擎优化教程