Springboot自定义mvc组件如何实现
如果你想实现一些定制化功能,只需要写这个组件,然后将它交给springboot管理,springboot会给我们自动装配
以下是spring官方文档解释
由官方文档可知,想要自定义组件,需要实现以下步骤
写一个配置类,加上@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; } }}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持好吧啦网。
相关文章:
1. vue-drag-chart 拖动/缩放图表组件的实例代码2. vue使用moment如何将时间戳转为标准日期时间格式3. Android studio 解决logcat无过滤工具栏的操作4. 什么是Python变量作用域5. js select支持手动输入功能实现代码6. PHP正则表达式函数preg_replace用法实例分析7. Android Studio3.6.+ 插件搜索不到终极解决方案(图文详解)8. bootstrap select2 动态从后台Ajax动态获取数据的代码9. Android 实现彻底退出自己APP 并杀掉所有相关的进程10. 一个 2 年 Android 开发者的 18 条忠告
