SpringBoot 之 扩展 SpringMVC
使用自定义视图解析器:
# src/main/java/com/wu/config/MyMvcConfig.java @Configuration // 标注这个类是一个配置类 public class MyMvcConfig implements WebMvcConfigurer { // 将视图解析器配置到容器中 @Bean public ViewResolver myViewResolver() { return new MyViewResolver(); } // 自定义一个视图解析器 public static class MyViewResolver implements ViewResolver { @Override public View resolveViewName(String viewName, Locale locale) throws Exception { return null; } } }
配置自定义视图跳转:
# src/main/java/com/wu/config/MyMvcConfig.java @Configuration // 标注这个类是一个配置类 public class MyMvcConfig implements WebMvcConfigurer { // 配置视图跳转 @Override public void addViewControllers(ViewControllerRegistry registry) { registry.addViewController("/").setViewName("index"); registry.addViewController("/index.html").setViewName("index"); } }
通过配置扩展 SpringMVC:
# 关闭thymeleaf缓存 spring.thymeleaf.cache=false # 设置项目路径 spring.servlet.context-path=/home # 配置日期格式化,默认为dd/MM/yyyy spring.mvc.date-format=yyyy-MM-dd
相关推荐
JudeJoo 2020-08-21
meleto 2020-08-15
玫瑰小妖 2020-07-18
dlutbob 2020-07-04
zmysna 2020-07-04
小鱿鱼 2020-06-26
MicroBoy 2020-06-17
zhongliwen 2020-06-13
zhongliwen 2020-06-13
qingjiuquan 2020-06-07
牧场SZShepherd 2020-06-03
zhangdy0 2020-05-31
spring艳 2020-05-30
方志朋 2020-05-30
咻pur慢 2020-05-27
mxcsdn 2020-05-27
牧场SZShepherd 2020-05-18
HappyHeng 2020-05-16