Thymeleaf3与Spring5集成报错Could not resolve view with name 'list2' in servlet


thymeleaf配置:
<? xml version ="1.0" encoding ="UTF-8" ?>
<beans xmlns ="http://www.springframework.org/schema/beans"
xmlns: xsi ="http://www.w3.org/2001/XMLSchema-instance"
xsi :schemaLocation ="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd" >

<!-- SpringResourceTemplateResolver automatically integrates with Spring's own -->
<!-- resource resolution infrastructure, which is highly recommended. -->
<bean id ="templateResolver" class ="org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver" >
<property name ="prefix" value ="/WEB-INF/templates/" />
<property name ="suffix" value =".html" />
<!-- HTML is the default value, added here for the sake of clarity. -->
<property name ="templateMode" value ="HTML" />
<!-- Template cache is true by default. Set to false if you want -->
<!-- templates to be automatically updated when modified. -->
<property name ="cacheable" value ="false" />
</bean>

<!-- SpringTemplateEngine automatically applies SpringStandardDialect and -->
<!-- enables Spring's own MessageSource message resolution mechanisms. -->
<bean id ="templateEngine" class ="org.thymeleaf.spring4.SpringTemplateEngine" >
<property name ="templateResolver" ref ="templateResolver" />
<!-- Enabling the SpringEL compiler with Spring 4.2.4 or newer can speed up -->
<!-- execution in most scenarios, but might be incompatible with specific -->
<!-- cases when expressions in one template are reused across different data -->
<!-- ypes, so this flag is "false" by default for safer backwards -->
<!-- compatibility. -->
<property name ="enableSpringELCompiler" value ="true" />
</bean>

<bean class ="org.thymeleaf.spring4.view.ThymeleafViewResolver" >
<property name ="templateEngine" ref ="templateEngine" />
<!-- NOTE 'order' and 'viewNames' are optional -->
<property name ="order" value ="1" />
<property name ="viewNames" value ="*.html,*.xhtml" />
</bean>
</beans>
Controller里面的配置:
@Controller
@RequestMapping ( "schedule" )
public class TimeScheduleController {

@RequestMapping ( "list2" )
public String list2 (){
return "list2" ;
}
}
启动后访问url:http://localhost:8080/schedule/list2报错,Could not resolve view with name 'list2' in servlet with name 'SpringMvc'

问题出现在配置文件中的viewNames配置: <property name ="viewNames" value ="*.html,*.xhtml" />
这是一个特殊设置,如果你项目里面全部使用的thymeleaf模板,这个配置可以去掉;如果你的项目里面还有jsp、freemarker等模板,这个的作用就是当你返回特定格式时(以.html或者.xhtml结尾的字符串)才会走thymeleaf模板配置。
这种情况改造有两种方式,
一、去掉viewName配置;
二、controller里面的return内容由“list2”改成“list2.html”。

参考:
  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值