spring boot如何配置视图解析器
1、spring是否自动装配了视图解析器ViewResolver,答案是肯定的,但是也需要你写配置文件。配置前缀后缀,和之前使用spring配置文件是一样的,只是简化了xml的配置,只需要两行即可解决配置。

3、@Bean@Conditional蚪嬷吃败OnMissingBeanpublic InternalResourceViewResolver defaultViewResolver() { InternalResourceViewResolver resolver = new InternalResourceViewResolver(); resolver.setPrefix(this.mvcProperties.getView().getPrefix()); resolver.setSuffix(this.mvcProperties.getView().getSuffix()); return resolver;}

5、继续查看源码发现:public static class View { private String prefix; private String suffix; public View() { public String getPrefix() { return this.prefix; }

7、源码查看到这里可以发现springboot对视图的封装,我们只需要在配置文件properties中配置,或者yaml文件配置ViewResolver的前缀和后缀即可。例子properties配置,yaml配置自行查看文档:spring.mvc.view.prefix=/views/spring.mvc.view.suffix=.jsp

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:62
阅读量:49
阅读量:34
阅读量:21
阅读量:45