springboot搭配thymeleaf访问html页面的时候,什么时候需要自定义前缀和后缀呢
为什么我全部使用默认配置会报错,必须自己定义前缀和后缀
解析器配置如下:
@Configuration public class WebMvcConfig extends WebMvcConfigurerAdapter implements ApplicationContextAware { //实现的这个接口能帮助我们设置spring的上下文 private ApplicationContext applicationContext; @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.applicationContext=applicationContext; } //对模板资源进行解析(模板资源解析器 @Bean @ConfigurationProperties(prefix = "spring.thymeleaf") public SpringResourceTemplateResolver templateResolver() { SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver(); templateResolver.setApplicationContext(this.applicationContext); templateResolver.setCharacterEncoding("UTF-8"); return templateResolver; } @Bean public SpringTemplateEngine templateEngine(){ SpringTemplateEngine templateEngine=new SpringTemplateEngine(); templateEngine.setTemplateResolver(templateResolver()); //设置支持spring el表达式 templateEngine.setEnableSpringELCompiler(true); return templateEngine; } //配置视图解析器 @Bean public ThymeleafViewResolver viewResolver(){ ThymeleafViewResolver viewResolver=new ThymeleafViewResolver(); viewResolver.setTemplateEngine(templateEngine()); return viewResolver; } }
thymeleaf属性只配置
控制器代码为:
启动项目后,访问http://localhost:8080/helloword就会报解析thymeleaf错误如下
这个报错真的很懵。求问为什么?