久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

Springboot自定義mvc組件如何實(shí)現(xiàn)

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

如果你想實(shí)現(xiàn)一些定制化功能,只需要寫(xiě)這個(gè)組件,然后將它交給springboot管理,springboot會(huì)給我們自動(dòng)裝配

以下是spring官方文檔解釋

Springboot自定義mvc組件如何實(shí)現(xiàn)

由官方文檔可知,想要自定義組件,需要實(shí)現(xiàn)以下步驟

寫(xiě)一個(gè)配置類,加上@Configuration注解 實(shí)現(xiàn)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(); } /** * 自定義視圖解析器,實(shí)現(xiàn)視圖解析器接口 */ public static class MyViewResolver implements ViewResolver{ @Override public View resolveViewName(String viewName, Locale locale) throws Exception { return null; } }}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 海南省| 晋州市| 老河口市| 塔城市| 抚顺县| 大名县| 柞水县| 南丹县| 绵竹市| 柏乡县| 承德县| 苗栗市| 江城| 资中县| 六盘水市| 石屏县| 织金县| 龙胜| 左贡县| 绍兴市| 东乡| 麻城市| 光泽县| 揭东县| 满洲里市| 盐城市| 雷山县| 高青县| 横山县| 兴城市| 上高县| 崇阳县| 丹巴县| 闸北区| 奉贤区| 漠河县| 黄浦区| 盐城市| 同心县| 富民县| 淮南市|