我的查看解析器无法找到合适的自由标记模板。
有没有办法告诉解析器bean和/或spring输出它正在寻找的文件路径?
即如果我的控制器返回viewName为“home”,我希望输出类似于“/WEB-INF/views/home.ftl”。
我的freemarker bean定义如下:
@Bean
public ViewResolver getViewResolver() {
FreeMarkerViewResolver resolver = new FreeMarkerViewResolver();
resolver.setCache(false);
resolver.setPrefix("");
resolver.setSuffix(".ftl");
return resolver;
}
@Bean
public FreeMarkerConfig getFreemarkerConfig() {
Properties props = new Properties();
props.setProperty("number_format","0.##");
props.setProperty("locale","en-GB");
Configuration configuration = new Configuration();
configuration.setDefaultEncoding("UTF-8");
FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
configurer.setFreemarkerSettings(props);
configurer.setConfiguration(configuration);
configurer.setTemplateLoaderPath("/WEB-INF/views/");
return configurer;
}
答案 0 :(得分:0)
Junits测试用例
@Test public void insert()抛出异常{ this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); mockMvc.perform(后( “/插入”))。andDo(打印()) .andExpect(状态()。ISOK()) .andExpect(forwardedUrl( “/ WEB-INF / test.jsp的”)); }
此处“insert”将替换为您的Request映射值和 “page”将替换为您期望spring将采取的相对位置