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

现在流行什么做网站seo文章排名优化

现在流行什么做网站,seo文章排名优化,网站自建系统,做公益网站需要哪些部门认证文章目录 Spring boot 2.0 升级到 3.3.1 的相关问题 (一)拦截器Interceptor的变动问题介绍解决方案 WebMvcConfigurerAdapter 自定义Mvc配置问题介绍解决方案 Spring boot 2.0 升级到 3.3.1 的相关问题 (一) 拦截器Interceptor的…

文章目录

  • Spring boot 2.0 升级到 3.3.1 的相关问题 (一)
    • 拦截器Interceptor的变动
      • 问题介绍
      • 解决方案
    • WebMvcConfigurerAdapter 自定义Mvc配置
      • 问题介绍
      • 解决方案

Spring boot 2.0 升级到 3.3.1 的相关问题 (一)

拦截器Interceptor的变动

问题介绍

在2.0 版本可以通过继承org.springframework.web.servlet.handler.HandlerInterceptorAdapter 类来实现一个拦截器,在2.4.0 版本开始标记为弃用,在3.3.1 版本已经没有这个类了,需要使用新的方式来实现。

解决方案

直接实现 org.springframework.web.servlet.HandlerInterceptor 接口即可。

原代码:

import com.abc.springboot.frame.constant.FrameConstant;
import com.abc.springboot.frame.pojo.dto.SystemSecurityRequestDTO;
import com.abc.springboot.frame.utils.RequestUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;/*** 检查客户端版本号拦截器*/
@Slf4j
public class CheckClientVersionInterceptor extends HandlerInterceptorAdapter {/*** 检查客户端版本是否有效*/@Autowiredprivate ICheckClientVersionHandler checkClientVersionHandler;/*** 请求处理前处理* @param request* @param response* @param handler* @return* @throws Exception*/@Overridepublic boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)throws Exception {//获取请求参数SystemSecurityRequestDTO requestDTO = RequestUtils.getAndSetSystemSecurityRequestDTO(request);//校验客户端版本号try{boolean checkResult =  checkClientVersionHandler.checkClientVersion(requestDTO,request.getHeader(FrameConstant.HTTP_HEADER_CLIENT_VERSION),request.getHeader(FrameConstant.HTTP_HEADER_CLIENT_TYPE));if(!checkResult){log.info("版本号不支持【{}】【{}】",requestDTO.getMethod(),requestDTO.getUri());request.getRequestDispatcher(FrameConstant.APPLICATION_URL_CLIENT_VERSION_VERIFY_FAILED).forward(request, response);return false;}return true;}catch (Exception e){log.warn("记录系统请求日志失败。",e);return false;}}
}

新代码


import com.abc.springboot.frame.constant.FrameConstant;
import com.abc.springboot.frame.pojo.dto.SystemSecurityRequestDTO;
import com.abc.springboot.frame.utils.RequestUtils;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerInterceptor;/*** 检查客户端版本号拦截器*/
@Slf4j
public class CheckClientVersionInterceptor implements HandlerInterceptor {/*** 检查客户端版本是否有效*/@Autowiredprivate ICheckClientVersionHandler checkClientVersionHandler;/*** 请求处理前处理* @param request* @param response* @param handler* @return* @throws Exception*/@Overridepublic boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)throws Exception {//获取请求参数SystemSecurityRequestDTO requestDTO = RequestUtils.getAndSetSystemSecurityRequestDTO(request);//校验客户端版本号try{boolean checkResult =  checkClientVersionHandler.checkClientVersion(requestDTO,request.getHeader(FrameConstant.HTTP_HEADER_CLIENT_VERSION),request.getHeader(FrameConstant.HTTP_HEADER_CLIENT_TYPE));if(!checkResult){log.info("版本号不支持【{}】【{}】",requestDTO.getMethod(),requestDTO.getUri());request.getRequestDispatcher(FrameConstant.APPLICATION_URL_CLIENT_VERSION_VERIFY_FAILED).forward(request, response);return false;}return true;}catch (Exception e){log.warn("记录系统请求日志失败。",e);return false;}}
}

WebMvcConfigurerAdapter 自定义Mvc配置

问题介绍

在2.0 版本可以通过继承org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter 类来实现自定义Mvc拦截器,在2.4.0 版本开始标记为弃用,在3.3.1 版本已经没有这个类了,需要使用新的方式来实现。

解决方案

org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter 类在 Spring Framework 5.0 之后被标记为已弃用,并在 Spring Boot 2.0 中不再推荐使用 。

替代方案有两种:

直接实现 WebMvcConfigurer 接口:
这是官方推荐的替代方法。WebMvcConfigurer 接口提供了多种默认方法(即带有实现的方法),允许开发者只实现所需的配置方法,而不必要实现接口中的所有方法。这种方式不会影响 Spring Boot 自身的 @EnableAutoConfiguration,允许 Spring Boot 的自动配置生效 。

继承 WebMvcConfigurationSupport 类:
另一种方法是继承 WebMvcConfigurationSupport 类。这个类提供了 Spring MVC 的默认配置,通过继承它,可以覆盖特定的方法来自定义配置。但请注意,使用这种方式将覆盖 Spring Boot 的自动配置,因此如果某个方法没有被重写,可能会导致相关功能的缺失,比如静态资源的处理 。

总结来说,如果你需要进行一些简单的自定义配置,并且想要保留 Spring Boot 的自动配置功能,推荐直接实现 WebMvcConfigurer 接口。如果你需要更全面的控制 Spring MVC 的配置,可以考虑继承 WebMvcConfigurationSupport 类,但要确保所有必要的配置都被正确覆盖和实现。

原代码

import com.abc.utils.formatter.LocalDateTimeFormatter;
import com.abc.utils.formatter.StringFormatter;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;import java.time.LocalDateTime;/*** 自定义的Mvc配置,用于配置格式化程序* @author 徐明龙 XuMingLong 2022-03-17*/
@Configuration
public class CustomWebMvcFormattersConfigurer extends WebMvcConfigurerAdapter  {@Overridepublic void addFormatters(FormatterRegistry registry) {//仅对Path方式传入的参数生效registry.addFormatterForFieldType(String.class, new StringFormatter());registry.addFormatterForFieldType(LocalDateTime.class, new LocalDateTimeFormatter());}
}

新代码

import com.abc.utils.formatter.LocalDateTimeFormatter;
import com.abc.utils.formatter.StringFormatter;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;import java.time.LocalDateTime;/*** 自定义的Mvc配置,用于配置格式化程序* @author 徐明龙 XuMingLong 2022-03-17*/
@Configuration
public class CustomWebMvcFormattersConfigurer implements WebMvcConfigurer {@Overridepublic void addFormatters(FormatterRegistry registry) {//仅对Path方式传入的参数生效registry.addFormatterForFieldType(String.class, new StringFormatter());registry.addFormatterForFieldType(LocalDateTime.class, new LocalDateTimeFormatter());}
}
http://www.ds6.com.cn/news/41546.html

相关文章:

  • 做印刷品去哪个网站软文推广发布平台
  • 做博客网站什么空间好软文网站有哪些
  • 海城网站制作建设上海高玩seo
  • 电子工程王北辰windows优化大师怎么使用
  • 张家界官方网站关键词优化按天计费
  • 网站建设seo视频百度seo快速排名优化软件
  • 网站设计与wap网站开发技术3322免费域名注册
  • 网站如何快速备案百度商业平台
  • 网站建设 cms上线了建站
  • 如何网站里做照片网络软文范例
  • 关于做美食的小视频网站佛山网站优化
  • 烟台专门做网站的广告平台
  • 网站建设管理调研提纲楼市最新消息
  • 盐城网站建设24gx驻马店百度seo
  • 购物网站中加减数目的怎么做活动推广文案
  • 电商网站建设毕业设计安卓优化大师hd
  • 建行官网官网网站吗打开浏览器直接进入网站
  • 营销网站开发哪家强手游推广去哪里找客源
  • 做网站要域名吗培训网页
  • 濮阳做网站多少钱百度世界排名
  • 久久建筑网站下载网站定制
  • 企业服务局宁波网站制作优化服务公司
  • 网站建设yingkagou蓝牙耳机网络营销推广方案
  • 有没有免费开网站的微信营销的案例
  • 用dw制作网站模板济南seo网站优化
  • 美空间网站最佳bt磁力猫
  • 济南市工程建设标准定额站网站企业网络营销方案设计
  • 工商营业执照注册网站百度网站官网网址
  • 网站建设案例收费吗日本进口yamawa
  • 58同城长沙回收网站建设设计网站免费素材