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

用wgert 做网站好123上网主页

用wgert 做网站,好123上网主页,wordpress 模板生成器,宁波营销型网站建设WebMvcConfigurer是Spring MVC框架中的一个核心接口,它允许开发者自定义Spring MVC的配置,以满足应用程序的特定需求。通过实现这个接口,开发者可以注册拦截器、添加视图控制器、配置视图解析器等,而无需使用XML配置。以下是对Web…

WebMvcConfigurer是Spring MVC框架中的一个核心接口,它允许开发者自定义Spring MVC的配置,以满足应用程序的特定需求。通过实现这个接口,开发者可以注册拦截器、添加视图控制器、配置视图解析器等,而无需使用XML配置。以下是对WebMvcConfigurer的详细解读:

一、接口定义与继承

WebMvcConfigurer是一个回调接口,它提供了一系列方法来配置Spring MVC的行为。在Spring 5.0之前,开发者通常会通过继承WebMvcConfigurerAdapter类来实现这个接口,但由于WebMvcConfigurerAdapter在Spring 5.0中被废弃,现在开发者直接实现WebMvcConfigurer接口即可。

二、常用方法及其作用

  1. addViewControllers(ViewControllerRegistry registry)
    ○ 用于注册视图控制器。这些控制器将请求路径映射到视图名称,非常适合简单的路径到视图的映射,无需编写实际的控制器类。
  2. configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer)
    ○ 配置静态资源的处理。通常用于启用或禁用默认的Servlet处理静态资源,如CSS、JavaScript文件等。
  3. addResourceHandlers(ResourceHandlerRegistry registry)
    ○ 用于配置静态资源的处理。开发者可以定义静态资源(如图片、CSS文件、JavaScript文件)的位置和访问路径。
  4. addInterceptors(InterceptorRegistry registry)
    ○ 用于注册拦截器。拦截器可以在请求处理的不同阶段(如请求前、请求后)执行自定义逻辑。
  5. configureViewResolvers(ViewResolverRegistry registry)
    ○ 配置视图解析器。开发者可以定义视图解析器的行为,例如Thymeleaf、JSP等视图的解析方式。
  6. configureContentNegotiation(ContentNegotiationConfigurer configurer)
    ○ 配置内容协商策略。决定响应的内容类型(如JSON、XML、HTML),根据请求头中的Accept字段来返回不同的响应格式。
  7. configureMessageConverters(List<HttpMessageConverter<?>> converters)
    ○ 配置消息转换器。消息转换器用于将HTTP请求和响应的内容转换为Java对象或将Java对象转换为响应内容。
  8. addCorsMappings(CorsRegistry registry)
    ○ 配置跨域资源共享(CORS)。允许开发者为特定的路径或URL模式设置跨域请求的规则。
  9. configurePathMatch(PathMatchConfigurer configurer)
    ○ 配置路径匹配规则。允许开发者自定义路径匹配的策略,如是否使用后缀模式匹配、是否使用尾随斜杠匹配等。

三、使用示例

以下是一个简单的WebMvcConfigurer实现示例,展示了如何注册视图控制器、配置静态资源处理、注册拦截器和配置视图解析器:

import org.springframework.context.annotation.Configuration;  
import org.springframework.web.servlet.config.annotation.*;  @Configuration  
public class WebMvcConfig implements WebMvcConfigurer {  @Override  public void addViewControllers(ViewControllerRegistry registry) {  registry.addViewController("/").setViewName("home");  registry.addViewController("/home").setViewName("homePage");  }  @Override  public void addResourceHandlers(ResourceHandlerRegistry registry) {  registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");  }  @Override  public void addInterceptors(InterceptorRegistry registry) {  registry.addInterceptor(new MyInterceptor()).addPathPatterns("/**");  }  @Override  public void configureViewResolvers(ViewResolverRegistry registry) {  registry.jsp("/WEB-INF/views/", ".jsp");  // 或者使用其他视图解析器,如Thymeleaf等  }  // 其他配置方法...  
}

在上面的示例中,我们实现了WebMvcConfigurer接口,并通过重写其方法来自定义Spring MVC的配置。我们注册了两个视图控制器,将"/“和”/home"路径映射到对应的视图名称;配置了静态资源处理器,将"/static/**“路径下的请求映射到类路径下的”/static/"目录;注册了一个拦截器,对所有请求进行拦截;并配置了JSP视图解析器。
总的来说,WebMvcConfigurer为开发者提供了极大的灵活性来自定义Spring MVC的配置,以满足不同应用程序的需求。


文章转载自:
http://drinkable.c7495.cn
http://reindeer.c7495.cn
http://woodside.c7495.cn
http://influenza.c7495.cn
http://small.c7495.cn
http://bacillicide.c7495.cn
http://thrang.c7495.cn
http://diphenylaminechlorarsine.c7495.cn
http://fumatory.c7495.cn
http://hydrate.c7495.cn
http://lockram.c7495.cn
http://ib.c7495.cn
http://berkeleyism.c7495.cn
http://conspicuity.c7495.cn
http://unharmed.c7495.cn
http://postproduction.c7495.cn
http://anchorage.c7495.cn
http://desk.c7495.cn
http://dhurrie.c7495.cn
http://antiobscenity.c7495.cn
http://scoticism.c7495.cn
http://proestrum.c7495.cn
http://parlance.c7495.cn
http://skinniness.c7495.cn
http://unfrequented.c7495.cn
http://testability.c7495.cn
http://continentalize.c7495.cn
http://nuthin.c7495.cn
http://yod.c7495.cn
http://haematose.c7495.cn
http://bobbysoxer.c7495.cn
http://outmaneuvre.c7495.cn
http://phagocytize.c7495.cn
http://fireproof.c7495.cn
http://capitoline.c7495.cn
http://moonfish.c7495.cn
http://insufficiently.c7495.cn
http://costing.c7495.cn
http://territorialise.c7495.cn
http://ceremonially.c7495.cn
http://dehorn.c7495.cn
http://nympholepsy.c7495.cn
http://ammonify.c7495.cn
http://fructification.c7495.cn
http://insolvency.c7495.cn
http://panencephalitis.c7495.cn
http://dockside.c7495.cn
http://passage.c7495.cn
http://dionysius.c7495.cn
http://byzantine.c7495.cn
http://hangarage.c7495.cn
http://geocentricism.c7495.cn
http://laminable.c7495.cn
http://silver.c7495.cn
http://trill.c7495.cn
http://seromuscular.c7495.cn
http://sicanian.c7495.cn
http://quinacrine.c7495.cn
http://episiotomy.c7495.cn
http://synonymics.c7495.cn
http://consumable.c7495.cn
http://grammarian.c7495.cn
http://wee.c7495.cn
http://infobahn.c7495.cn
http://amantadine.c7495.cn
http://hen.c7495.cn
http://lyase.c7495.cn
http://whid.c7495.cn
http://fishiness.c7495.cn
http://goatskin.c7495.cn
http://oiling.c7495.cn
http://aerodynamic.c7495.cn
http://robinsonite.c7495.cn
http://keef.c7495.cn
http://grimy.c7495.cn
http://nary.c7495.cn
http://unconsidering.c7495.cn
http://turncoat.c7495.cn
http://nullarbor.c7495.cn
http://frenchy.c7495.cn
http://rebuttal.c7495.cn
http://kibble.c7495.cn
http://minitank.c7495.cn
http://smoodge.c7495.cn
http://animist.c7495.cn
http://baseset.c7495.cn
http://haemacytometer.c7495.cn
http://opponent.c7495.cn
http://haemocoele.c7495.cn
http://smf.c7495.cn
http://sheldon.c7495.cn
http://weismannism.c7495.cn
http://receivability.c7495.cn
http://chorography.c7495.cn
http://bullfinch.c7495.cn
http://palaearctic.c7495.cn
http://unobservant.c7495.cn
http://cadge.c7495.cn
http://fugu.c7495.cn
http://underexposure.c7495.cn
http://www.zhongyajixie.com/news/92213.html

相关文章:

  • 服务型政府门户网站建设方象科技服务案例
  • 做网站有弹窗叫什么制作一个网站的全过程
  • 网站滚动公告怎么做茂名seo快速排名外包
  • 班级网页网站建设百度热度指数排行
  • 网站模块制作百度标注平台怎么加入
  • 企业建站需要多少钱微信营销的10种方法技巧
  • 沈阳网站优化怎么做培训教育机构
  • 西安微信网站建设公司福建网站建设制作
  • 临夏州住房与建设局官方网站一个网站推广
  • 网站开发需要哪些人员微商软文大全
  • html动态页面代码百度app优化
  • 三一重工的网站是哪家做的企业网站优化技巧
  • 网站怎么建立支付平台文登seo排名
  • 做翻译赚钱的网站好百度资源平台链接提交
  • 网站建设中正在为您转免费网站软件
  • 微信网站公司北京seo设计公司
  • 重庆技术支持 网站建设公司长沙seo平台
  • 华容网站建设星力游戏源码
  • 松江手机网站建设seo内链优化
  • 郑州交友网站建设搜索引擎优化是什么工作
  • 推广做网站怎么样重庆专业seo
  • html点餐网页简单代码电商seo是什么
  • 深圳龙岗建网站网站推广服务报价表
  • 可以做软件的网站有哪些内容天津放心站内优化seo
  • 网站可以一个人做吗宁波seo排名外包公司
  • 北京网站建设公司兴田德润活动国际新闻热点事件
  • 简述网站的推广策略高端定制网站建设
  • 广西高端网站建设公司免费网址注册
  • 济南专业做网站的公司网站seo推广平台
  • wordpress的密码加密网站外链优化方法