【发布时间】:2018-11-29 23:01:51
【问题描述】:
控制器:
@Controller
public class WeatherController {
@GetMapping("/weather")
public String weatherForm(Model model){
model.addAttribute("weather",new WeatherServiceImpl());
return "weather";
}
@PostMapping("/weather")
public String weatherSubmit(@ModelAttribute WeatherServiceImpl weather) {
return "result";
}
}
模板
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Getting Started: Handling Form Submission</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h1>Form</h1>
<form action="#" th:action="@{/weather}" th:object="${weather}" method="post">
<p>City: <input type="text" th:field="*{city}" /></p>
<p><input type="submit" value="Submit" /> <input type="reset" value="Reset" /></p>
</form>
</body>
</html>
结果模板
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Getting Started: Handling Form Submission</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h1>Result</h1>
<p th:text="'city: ' + ${weather.city}" />
<a href="/weather">Submit another message</a>
</body>
</html>
所以我正在尝试使用表单从用户那里获取城市名称并将其解析为对象。它解析为对象。但是我尝试显示我从 /weather 获得的城市名称,它不会转到 /result 并且会显示一条错误消息 白标错误页面 此应用程序没有显式映射 /error,因此您将其视为后备。
2018 年 6 月 20 日星期三 20:42:53 EEST 出现意外错误(类型=内部服务器错误,状态=500)。 模板解析时出错(模板:“类路径资源[templates/result.html]”)
【问题讨论】:
标签: java spring spring-mvc model-view-controller