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

山东德州网站建设哪家最好seo优化的搜索排名影响因素主要有

山东德州网站建设哪家最好,seo优化的搜索排名影响因素主要有,品牌授权网站,中国做民宿的网站WebMvcConfigurer 是 Spring MVC 提供的一个扩展接口,用于配置 Spring MVC 的各种功能。在 Spring Boot 应用中,通过实现 WebMvcConfigurer 接口,可以定制和扩展默认的 Spring MVC 配置。WebMvcConfigurer 接口提供了一组回调方法&#xff0c…

WebMvcConfigurer 是 Spring MVC 提供的一个扩展接口,用于配置 Spring MVC 的各种功能。在 Spring Boot 应用中,通过实现 WebMvcConfigurer 接口,可以定制和扩展默认的 Spring MVC 配置。WebMvcConfigurer 接口提供了一组回调方法,用于配置 Spring MVC 的各种方面,如视图解析器、拦截器、跨域请求、消息转换器等。通过实现这些方法,可以方便地自定义 MVC 配置。

1. 创建配置类

创建一个配置类并实现 WebMvcConfigurer 接口,通常加上 @Configuration 注解使其成为配置类。

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;@Configuration
@EnableWebMvc
public class MyWebMvcConfig implements WebMvcConfigurer {// 自定义配置在这里添加
}

2. 配置视图解析器

通过实现 configureViewResolvers 方法,可以自定义视图解析器。

import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;@Override
public void configureViewResolvers(ViewResolverRegistry registry) {registry.jsp("/WEB-INF/views/", ".jsp");
}
​

3. 添加拦截器

通过实现 addInterceptors 方法,可以添加拦截器。

@Override
public void addInterceptors(InterceptorRegistry registry) {registry.addInterceptor(new MyInterceptor()).addPathPatterns("/**").excludePathPatterns("/login", "/css/**");
}
  • addInterceptor: 添加自定义拦截器。
  • addPathPatterns: 指定拦截路径。
  • excludePathPatterns: 排除某些路径不拦截

4. 配置跨域请求

通过实现 addCorsMappings 方法,可以配置跨域请求。

@Override
public void addCorsMappings(CorsRegistry registry) {registry.addMapping("/api/**").allowedOrigins("http://example.com").allowedMethods("GET", "POST").allowCredentials(true);
}

注意事项

  • 不要继承 WebMvcConfigurationSupport:除非你想完全接管 Spring MVC 配置。否则推荐直接实现 WebMvcConfigurer。
  • 多个配置类:如果有多个类实现了 WebMvcConfigurer,可以使用 @Order 控制顺序。
  • Spring Boot 2.x 及以上兼容性良好:大多数配置开箱即用,无需额外依赖。

5. 添加静态资源处理

通过实现 addResourceHandlers 方法,可以配置静态资源的处理。 

import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
}
​

6. 配置消息转换器

通过实现 configureMessageConverters 方法,可以添加或自定义消息转换器。

import org.springframework.http.converter.HttpMessageConverter;@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {converters.add(new MyCustomMessageConverter());
}
​

权限完整例子

import java.util.concurrent.ExecutorService;
import net.hworld.interceptor.AccessInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.support.TaskExecutorAdapter;
import org.springframework.web.servlet.config.annotation.AsyncSupportConfigurer;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;@Configuration(proxyBeanMethods = false)
public class WebMvcConfig implements WebMvcConfigurer {@Autowiredprivate AccessInterceptor accessInterceptor;@Autowiredprivate ExecutorService executorService;@Overridepublic void addInterceptors(InterceptorRegistry registry) {registry.addInterceptor(accessInterceptor).order(2).addPathPatterns("/**").excludePathPatterns("/actuator/**", "/favicon.ico", "/demo/**");}@Overridepublic void configureAsyncSupport(AsyncSupportConfigurer configurer) {configurer.setTaskExecutor(new TaskExecutorAdapter(executorService));}
}

接口认证 

/*** 权限判断*/
@Slf4j
@Component
@Order(2)
public class AccessInterceptor implements HandlerInterceptor {@Autowiredprivate AuthUtils authUtils;@Overridepublic boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)throws Exception {if (handler instanceof HandlerMethod) {HandlerMethod method = (HandlerMethod) handler;//内网不需要tokenNotVerifyToken notVerifyTokenCls = method.getMethod().getDeclaringClass().getAnnotation(NotVerifyToken.class);NotVerifyToken notVerifyTokenMtd = method.getMethod().getAnnotation(NotVerifyToken.class);if (notVerifyTokenCls != null || notVerifyTokenMtd != null) {return true;}// 认证String authorization = request.getHeader(HttpHeaders.AUTHORIZATION);if (StringUtils.isBlank(authorization)){authorization = request.getParameter("accessToken");}if (StringUtils.isNotBlank(authorization)) {authorization = authorization.replace("Bearer ", "");log.info("authorization is {}", authorization);try {authUtils.authorize(authorization, false);} catch (RuntimeException e) {log.warn("token error 401: {},{}", authorization, e.getMessage());this.handle401(response, WebResponse.fail(WebResponseCode.AUTH_EXCEPTION));return false;}} else {log.warn("token is empty");this.handle401(response, WebResponse.fail(WebResponseCode.AUTH_EXCEPTION));return false;}}return true;}void handle401(HttpServletResponse response, WebResponse<Object> webResponse) throws IOException {response.setStatus(HttpStatus.OK.value());response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);IOUtils.write(JsonUtil.bean2Json(webResponse), response.getWriter());response.getWriter().close();}}

绕开认证注解

@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface NotVerifyToken {}

http://www.dtcms.com/wzjs/112407.html

相关文章:

  • 加盟网网站建设策划书建站工具
  • ios 常用网站淘宝seo是什么意思啊
  • 推广做网站怎么样杭州seo关键词优化公司
  • 为什么搜索不到刚做的网站北京seo网络优化招聘网
  • 建设ca网站口碑营销策略
  • 青海建设兵团青岛战友网站seo技术分享免费咨询
  • 广州冼村疫情网络营销郑州优化推广公司
  • 南京百度网站制作工具站seo
  • 网站开发研如何快速推广网上国网
  • 电子商务网站建设评估的工具网络推广方案范例
  • wordpress做导航网站百度指数电脑版
  • 网页站点的建立流程全国疫情高峰感染高峰进度查询
  • 新增网站推广教程网络推广引流是做什么的
  • 付费 视频 网站 怎么做seo优化推广软件
  • 360推广 网站建设在线数据分析网站
  • 东莞市研发网站建设品牌微信小程序开发费用一览表
  • 桥 网站建设百度指数疫情
  • 跨境电商网站排行榜曼联目前积分榜
  • 广州建设网站平台网站seo培训
  • 网站推广及建设ppt站内推广的方法和工具
  • 网页设计与制作教程知识点总结seo顾问张智伟
  • 大连招投标信息网seo网站推广助理
  • 河北汉佳 做网站的公司东莞公司网上推广
  • 怎么做网站后端百度网站推广排名
  • 做网站怎么加水平线外贸网站优化公司
  • 做拍卖网站有哪些衡阳百度推广
  • 重庆网站建设运营网页设计大作业
  • 昆明制作企业网站站长工具搜索
  • 馆陶网站建设电商自学网
  • 南阳响应式网站制作网站seo内容优化