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

三站合一网站建设方案网站搜索引擎优化的步骤

三站合一网站建设方案,网站搜索引擎优化的步骤,软件开发网站开发副业,有没专门做二手的家具网站说明#xff1a; 一些版本比较老的spring框架的#xff0c;是通过继承HandlerInterceptorAdapter并重写preHandle()方法#xff0c;和继承WebMvcConfigurerAdapter并重写 addInterceptors()方法来实现拦截器的#xff0c;但是这两个类很久前就已经过时了#xff0c;不推荐…说明 一些版本比较老的spring框架的是通过继承HandlerInterceptorAdapter并重写preHandle()方法和继承WebMvcConfigurerAdapter并重写 addInterceptors()方法来实现拦截器的但是这两个类很久前就已经过时了不推荐使用推荐使用下面两个接口。 以接口接口限流进行具体的操作自定义拦截器主要步骤就是两个 1、实现HandlerInterceptor并实现rpreHandle前置处理方法 2、实现WebMvcConfigurer并实现addInterceptors增加拦截器方法把自定义的拦截器增加到spring容器中 HandlerInterceptor拦截器处理器接口有三个接口 ● preHandle在业务处理器处理请求之前被调用。预处理可以进行编码、安全控制、权限校验等处理 ● postHandle在业务处理器处理请求执行完成后生成视图之前执行。后处理调用了Service并返回ModelAndView但未进行页面渲染有机会修改ModelAndView ● afterCompletion在DispatcherServlet完全处理完请求后被调用可用于清理资源等。返回处理已经渲染了页面 实操 1、引入依赖 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-aop/artifactId /dependency !--Redis依赖-- dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-data-redis/artifactId /dependency2、自定义接口访问注解 /** * 接口访问限制枚举 * author ppp * date 2023/2/14 */ Target({ElementType.METHOD}) Retention(RetentionPolicy.RUNTIME) public interface AccessLimit {/*** return 访问最大次数*/int accessMaxTimes() default 60;/*** return 时间*/long timeOut() default 1;/*** return 时间单位*/TimeUnit timeUnit() default TimeUnit.MINUTES; }3、自定义拦截器配置 同时实现HandlerInterceptorWebMvcConfigurer实现preHandle和addInterceptors方法 /** * 接口访问限制拦截器配置 * author ppp * date 2023/2/14 */ Component public class AccessLimitInterceptorConfig implements HandlerInterceptor, WebMvcConfigurer {private final static String KEY Redis_accessLimit_key;AutowiredRedisTemplate redisTemplate;AutowiredAccessLimitInterceptorConfig accessLimitInterceptorConfig;Overridepublic boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {//判断请求是否属于方法的请求if(handler instanceof HandlerMethod){HandlerMethod hm (HandlerMethod) handler;//获取方法中的注解,看是否有该注解AccessLimit accessLimit hm.getMethodAnnotation(AccessLimit.class);if(accessLimit null){return true;}int accessMaxTimes accessLimit.accessMaxTimes();long timeOut accessLimit.timeOut();TimeUnit timeUnit accessLimit.timeUnit();// 如果redis不存在或已经过期Long expire redisTemplate.opsForValue().getOperations().getExpire(KEY);if (!redisTemplate.hasKey(KEY) || Objects.requireNonNull(expire).intValue() 0) {redisTemplate.opsForValue().set(KEY, 1, timeOut, timeUnit);} else {long increment redisTemplate.opsForValue().increment(KEY).intValue();if (increment accessMaxTimes) {throw new RuntimeException(访问已经超过最大值 accessMaxTimes);}}}return true;}Overridepublic void addInterceptors(InterceptorRegistry registry) {registry.addInterceptor(accessLimitInterceptorConfig);} }4、配置redis /*** Redis管理配置*/ Configuration public class RedisConfigurer {/*** 设置 redisTemplate 的序列化设置** param redisConnectionFactory* return*/Beanpublic RedisTemplateObject, Object redisTemplate(RedisConnectionFactory redisConnectionFactory) {RedisTemplateObject, Object template new RedisTemplate();template.setConnectionFactory(redisConnectionFactory);GenericToStringSerializer genericToStringSerializer new GenericToStringSerializer(Object.class);template.setValueSerializer(genericToStringSerializer);template.setKeySerializer(new StringRedisSerializer());template.setHashKeySerializer(new StringRedisSerializer(Charset.forName(UTF-8)));template.setHashValueSerializer(new StringRedisSerializer(Charset.forName(UTF-8)));template.afterPropertiesSet();return template;}Beanpublic CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) {return new RedisCacheManager(RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory),this.getRedisCacheConfigurationWithTtl(24 * 60 * 60), // 默认策略未配置的 key 会使用这个this.getRedisCacheConfigurationMap() // 指定 key 策略);}private MapString, RedisCacheConfiguration getRedisCacheConfigurationMap() {MapString, RedisCacheConfiguration redisCacheConfigurationMap new HashMap();return redisCacheConfigurationMap;}private RedisCacheConfiguration getRedisCacheConfigurationWithTtl(Integer seconds) {RedisCacheConfiguration redisCacheConfiguration RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofSeconds(seconds));return redisCacheConfiguration;} }5、使用 /*** 一分钟内最多请求10次* param content*/ AccessLimit(accessMaxTimes 10, timeOut 1, timeUnit TimeUnit.MINUTES) GetMapping(/sendEvent) public void sendEvent(RequestParam String content) {testService.send(content); }
http://www.dnsts.com.cn/news/196615.html

相关文章:

  • 永康电子商务网站建设顺德建设行政主管部门网站
  • 建设网站平台滴滴车设计感网站有哪些方面
  • 可以做微课PPT模板 网站办公室隔断
  • 东莞市行业网站制作公司网站开发 pdf
  • 微网站开发建设win10如何部署自己做的网站
  • seo顾问和seo专员安徽优化推广
  • 海宁网站设计好看的手机网站布局
  • 南京制作手机网站包头教育平台网站建设
  • 网站建设百灵鸟优化可以看网站的浏览器有哪些
  • 华美天一建筑公司网站网站建设的科目
  • 小榄网站开发wordpress title插件
  • 交易类网站seo怎么做湖北seo优化诊断
  • 网站线上推广方式广告设计作品集
  • 湖北省建设厅官方网站微信导航网站如何建设
  • vs2010怎么做网站前台商洛网站建设哪家好
  • 珠海专业做网站制作单页设计风格
  • 申请号的网站品牌建设目标包括哪些方面
  • 建设一个公司网站需要什么知识宣传片影视拍摄公司
  • 网站建设策划ppt张店做网站公司
  • 鹤山做网站公司seo云优化方法
  • 深圳网站. 方维网络手机 网站内 搜索
  • 给网站底部做友情链接国内优秀门户网站设计
  • 在哪一个网站做社保申报做语音聊天网站要多少钱
  • 上海公司网站建设以子wordpress 加入js
  • 有什么好的书写网站腾讯云域名价格
  • 长春网站制作长春万网电子商务平台方案
  • ui设计培训资料合肥网站seo推广
  • 网站和网页的设计原则管理者应具备的能力
  • 大庆做网站找谁微信开发网站建设程序
  • 静态html网站打包成exe企业邮箱注册账号