国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

Springboot自定義mvc組件如何實現

瀏覽:115日期:2023-04-07 18:34:11

如果你想實現一些定制化功能,只需要寫這個組件,然后將它交給springboot管理,springboot會給我們自動裝配

以下是spring官方文檔解釋

Springboot自定義mvc組件如何實現

由官方文檔可知,想要自定義組件,需要實現以下步驟

寫一個配置類,加上@Configuration注解 實現WebMvcConfigurer接口 不添加@EnableWebMvc注解

示例:自定義視圖解析器

package com.yl.config;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.web.servlet.View;import org.springframework.web.servlet.ViewResolver;import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;import java.util.Locale;/** * mvc配置類 */@Configurationpublic class MyMvcConfig implements WebMvcConfigurer { /** * 將自定義視圖解析器配置成bean存入spring */ @Bean public ViewResolver myViewResovler(){ return new MyViewResolver(); } /** * 自定義視圖解析器,實現視圖解析器接口 */ public static class MyViewResolver implements ViewResolver{ @Override public View resolveViewName(String viewName, Locale locale) throws Exception { return null; } }}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Spring
相關文章:
主站蜘蛛池模板: 化德县| 乐平市| 遂平县| 阿拉善盟| 永春县| 连山| 瑞丽市| 仁化县| 乌鲁木齐县| 柳河县| 蕲春县| 尚志市| 五指山市| 偃师市| 昌黎县| 阿城市| 商洛市| 廊坊市| 吴堡县| 成都市| 尖扎县| 蒙阴县| 四平市| 峡江县| 弥渡县| 卓尼县| 顺平县| 和平县| 罗定市| 长治县| 张家川| 垣曲县| 贺州市| 北碚区| 平邑县| 女性| 邵东县| 江永县| 克东县| 荥经县| 南汇区|