logo资料库

Springboot视图解析器ViewResolver使用实例.pdf

第1页 / 共2页
第2页 / 共2页
资料共2页,全文预览结束
视图解析器ViewResolver使用实例 使用实例 Springboot视图解析器 主要介绍了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; }
} } 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。
分享到:
收藏