最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Springboot视图解析器ViewResolver如何使用 Springboot视图解析器ViewResolver使用实例
时间:2020-04-07 编辑:袖梨 来源:一聚教程网
Springboot视图解析器ViewResolver如何使用?本篇文章小编给大家分享一下Springboot视图解析器ViewResolver使用实例,小编觉得挺不错的,有需要的小伙伴们可以来看看。
SpringMVC提供的ViewResolver可以分为两大类:面向单一视图和面向多视图类型。所谓面向单一视图指可通过视图模板的位置来定位视图,面向多视图需要额外的配置文件来确定视图。
项目结构如下(Idea)
代码
package com.syu.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.WebMvcConfigurer; import java.util.Locale; //若你想diy一些定制化的功能,只需要写这个组件,然后将它交给SpringBoot //扩展SpringMVC dispatchservlet @Configuration public class MyMvcConfig implements WebMvcConfigurer { //ViewResolver 实现了试图解析器的接口的类,我们就可以把它看作一个视图解析器 @Bean public ViewResolver myViewResolver(){ return new MyViewResolver(); } public static class MyViewResolver implements ViewResolver{ @Override public View resolveViewName(String s, Locale locale) throws Exception { return null; } } }
相关文章
- SpringBoot自定义bean绑定解析 10-24
- Javaweb工程运行报错HTTP Status 404解决教程 10-20
- JAVA获取jvm和操作系统相关信息方法 10-20
- BeanFactory和FactoryBean的区别讲解 10-20
- 微信小程序的宿主环境实现教程 10-10
- dispatchEvent解决重叠元素响应事件教程 10-10