An error happened during template parsing (template: “class path resource [templates/index.html]“)

An error happened during template parsing (template: “class path resource [templates/index.html]”)OC

在开发springboot的时候,进行modelAndView 视图层映射的时候,一直出现

An error happened during template parsing (template: “class path resource [templates/index.html]”)

模板解析过程中发生错误(模板:“类路径资源[templates/index.html]”)

解决办法

在试了网上各种方法后,我发现先并不是Java代码的错误,很可能是idea犯病。

spring boot使用的thymeleaf语言对后端传过来的参数进行取值时有两种方式th:text="emp.getId()"th:text="emp.id",前面一种方式我使用的时候一直报错,就是上面所说的“类资源路径解析不到”,在我改成下面的代码后,成功解决!

成功解决后的代码块

<tr th:each="emp:${emps}">
	<td th:text="${emp.id}"></td>
	<td th:text="${emp.lastName}"></td>
	<td th:text="${emp.email}"></td>
	<td th:text="${emp.gender}==1?'男':'女'"></td>
	<td th:text="${emp.department.departmentName}"></td>
	<td th:text="${#dates.format(emp.birth, 'yyyy-MM-dd')}"></td>
	<td>
		<button class="btn btn-sm btn-primary">编辑</button>
		<button class="btn btn-sm btn-danger">删除</button>
	</td>
</tr>

版权声明:本文为weixin_42324146原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。