Mapleyang

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
统计
 

SpringMVC扩展

implements WebMvcConfigurer,重写一些方法

复制代码
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
    //ViewResolver 实现了视图解析器接口的类,我们就可以把它看做视图解析器
    @Bean
    public ViewResolver myViewResolver(){
        return new NyViewResolver();
    }

    public static class NyViewResolver implements ViewResolver{

        @Override
        public View resolveViewName(String viewName, Locale locale) throws Exception {
            return null;
        }
    }
}
复制代码

 

 

Thymeleaf

模板引擎的使用:第一步:引入Thymeleaf

  • Thymeleaf官网:https://www.thymeleaf.org/

  • Thymeleaf在Github的主页:https://github.com/thymeleaf/thymeleaf

  • spring官方文档【springboot参考指南】:https://docs.spring.io/spring-boot/docs/2.1.6.RELEASE/reference/htmlsingle/#using-boot-starter

结论:要使用thymeleaf,只需要导入对应的依赖就可以了!我们将HTML放在我们的templates目录下即可!

public static final String DEFAULT_PREFIX="classpath:/templates/";

public static final String DEFAULT_SUFFIX=".html";

 

修改日期格式,下面这个已经弃用,建议用注解

spring.mvc.date-format=

修改日期注解

@DateTimeFormat(pattern = "yyyy-MM-dd")

 

扩展springmvc 官方建议这样做

复制代码
//如果我们要扩展springmvc,官方建议我们这样做
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
    //重写视图跳转方法
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //addViewController添加一个视图,浏览器输入/maple 就会跳转到test页面
        registry.addViewController("/maple").setViewName("text");
    }
}
复制代码

 

posted on   折木~  阅读(38)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
 
点击右上角即可分享
微信分享提示