日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Spring boot的Spring MVC扩展功能

發(fā)布時間:2025/3/20 javascript 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring boot的Spring MVC扩展功能 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Spring中
配置interceptors

<mvc:view-controller path="/hello" view-name="success"/> <mvc:interceptors><mvc:interceptor><mvc:mapping path="/hello"/><bean></bean></mvc:interceptor> </mvc:interceptors> <mvc:default-servlet-handler/>

Spring boot實現(xiàn)方式

參考官網(wǎng)
https://docs.spring.io/spring-boot/docs/1.5.10.RELEASE/reference/htmlsingle/#boot-features-developing-web-applications

可以擴(kuò)展Spring MVC功能
編寫一個配置類@Configuration

是WebMvcConfigurerAdapter類型,不能標(biāo)注@EnableWebMvc
既保留了所有的自動配置,也能用自定義擴(kuò)展的配置

//使用WebMvcConfigurerAdapter可以來擴(kuò)展SpringMVC的功能 //@EnableWebMvc 不要接管SpringMVC @Configuration public class MyMvcConfig extends WebMvcConfigurerAdapter {@Overridepublic void addViewControllers(ViewControllerRegistry registry) {// super.addViewControllers(registry);//瀏覽器發(fā)送 /atguigu 請求來到 successregistry.addViewController("/atguigu").setViewName("success");} }

實現(xiàn)原理

WebMvcAutoConfiguration
SpringMVC的自動配置類

搜索,WebMvcAutoConfigurationAdapter

EnableWebMvcConfiguration
在做其他自動配置時會導(dǎo)入

@Import(EnableWebMvcConfiguration.class)

DelegatingWebMvcConfiguration
搜索,setConfigurers

從容器中獲取,所有的WebMvcConfigurer

addViewControllers
從容器中獲取,所有的WebMvcConfigurer

把它們的addViewControllers方法,都調(diào)用一遍

addViewControllers
將所有的WebMvcConfigurer相關(guān)配置,都一起來調(diào)用

就都會一起,來起作用

容器中
所有的WebMvcConfigurer都會一起起作用
自定義的配置類,也會被調(diào)用

自動配置類,其作用的時候,會掃描容器中
所有的配置類,自定義的配置類,也會掃描到
SpringMVC的自動配置,和自定義的擴(kuò)展配置都會起作用

《新程序員》:云原生和全面數(shù)字化實踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀

總結(jié)

以上是生活随笔為你收集整理的Spring boot的Spring MVC扩展功能的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。