网站首页 美食营养 游戏数码 手工爱好 生活家居 健康养生 运动户外 职场理财 情感交际 母婴教育 时尚美容

SpringBoot如何扩展与全面接管SpringMVC

时间:2024-10-13 12:07:07

1、在实际开发过程中,仅仅是SpringBoot集成的功能使用SpringMVC是仅仅不够的,比如: <mvc:view-controller path=/success view-name=success/> <mvc:default-servlet-handler/> <mvc:annotation-driven></mvc:annotation-driven>

SpringBoot如何扩展与全面接管SpringMVC

3、使用WebMvcConfigurerAdapter可以来扩展SpringMVC的功能,比如浏览器发送/bg请求来到success视图。代码中的双引号已经被删除,请自行加上package com.gwolf.config;import org.springframework.context.annotation.Configuration;import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;@Configurationpublic class MyMvcConfig extends WebMvcConfigurerAdapter{ @Override public void addViewControllers(ViewControllerRegistry registry) { registry.addViewController(/bg).setViewName(success); }}

SpringBoot如何扩展与全面接管SpringMVC

5、EnableWebMvcConfiguration会加载容器中所有的WebMvcConfigurer一起起作用。这样SpringMVC的自动配置和我们的配置类也会被调用。

SpringBoot如何扩展与全面接管SpringMVCSpringBoot如何扩展与全面接管SpringMVC
© 2025 小知经验
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com