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"); } }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南