对于 Spring-boot 应用程序,我无法使用 Thymeleaf 从 HTML 文件加载浏览器中的输入和实例值。
下面是控制器 java 文件中的代码片段。
@RequestMapping(value = "/x")
public String launch(@RequestParam("inputFile") String inputFile, @RequestParam("instance") int instance) {
...
ModelAndView mav = new ModelAndView();
Map<String, String> parameters = new HashMap<>();
parameters.put("inputFile", inputFile);
parameters.put("instance", Integer.toString(instance));
mav.addObject("parameters", parameters);
mav.setViewName("welcome");
return "welcome";
}
这是welcome.html 中的代码:
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Title</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<div class="container">
<div class="starter-template">
<h1>Success!</h1>
<h2><span th:text="inputFile: ${parameters.inputFile}"></span></h2>
<h3><span th:text="instance: ${parameters.instance}"></span></h3>
</div>
</div>
</body>
</html>
这是我在浏览器上收到的错误:
无法解析为表达式:“inputFile:$ {parameters.inputFile}”(欢迎:16)
尝试以下解决方案之一。
解决方案一:
<table>
<tr th:each="element : ${parameters}">
<td th:text="${element.key}">keyvalue</td>
<table>
<tr th:each="elementSingle : ${element.value}">
<td th:text="${elementSingle.name}">Some name</td>
<td th:text="${elementSingle.description}">Description</td>
</tr>
</table>
</tr>
</table>
解决方案2:
<table class="table table-striped">
<tr>
<th>Board Name</th>
<th>Investor</th>
<th>Fuse Manufacturer</th>
<th>Fuse Nr. Of Poles</th>
<th>Fuse Characteritics</th>
<th>Fuse Amount</th>
</tr>
<th:block th:each="item: ${map}">
<tr th:each="fuse: ${item.value}">
<td th:text="${item.key.name}" />
<td th:text="${item.key.investor}" />
<td th:text="${fuse.fuse.manufacturer.name}" />
<td th:text="${fuse.fuse.type}" />
<td th:text="${fuse.fuse.characteristics}" />
<td th:text="${fuse.quantity}" />
</tr>
</th:block>
</table>
解决方案3:
<tr th:each="instance : ${parameters}">
<td th:text="${instance.key}">keyvalue</td>
<td th:text="${instance.value.fieldName}">num</td>
</tr>
注意:根据您的代码设置变量。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)