我从->>> https://www.baeldung.com/spring-mvc-form-tutorial
我不知道为什么,但是代码不起作用。
我试图更改目录,名称,在属性中添加了奇怪的内容,但是一切都失败了。
spring.view.prefix= /WEB-INF/jsp/
spring.view.suffix= .jsp
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<html>
<head>
</head>
<body>
<form:form method="POST"
action="${pageContext.request.contextPath}/addFlightDTO" modelAttribute="FlightDTO">
<table>
<tr>
<td><form:label path="DateFrom">DateFrom</form:label></td>
<td><form:input path="DateFrom"/></td>
</tr>
<tr>
<td><form:label path="DateTo">DateTo</form:label></td>
<td><form:input path="DateTo"/></td>
</tr>
<tr>
<td><form:label path="Origin">Origin</form:label></td>
<td><form:input path="Origin"/></td>
</tr>
<tr>
<td><form:label path="Departure">Departure</form:label></td>
<td><form:input path="Departure"/></td>
</tr>
<tr>
<td><form:label path="currency">currency</form:label></td>
<td><form:input path="currency"/></td>
</tr>
<tr>
<td><input type="submit" value="Submit"/></td>
</tr>
</table>
</form:form>
</body>
</html>
public class FlightDTO {
private String DateFrom;
private String DateTo;
private String Origin;
private String Departure;
private Double currency;
getters, setters ...
@Controller
public class FormController {
@RequestMapping(value = "/FlightDTO", method = RequestMethod.GET)
public ModelAndView showForm() {
return new ModelAndView("Forms", "FlightDTO", new FlightDTO());
}
@RequestMapping(value = "/addFlightDTO", method = RequestMethod.POST)
public String submit(@Valid @ModelAttribute("FlightDTO")FlightDTO flightDTO,
BindingResult result, ModelMap model) {
if (result.hasErrors()) {
return "error.jsp";
}
model.addAttribute("DateFrom", flightDTO.getDateFrom());
model.addAttribute("DateTo", flightDTO.getDateTo());
model.addAttribute("currency", flightDTO.getCurrency());
return "Results";
}
}
错误消息
THYMELEAF][http-nio-8080-exec-5] Exception processing template "Forms": Error resolving template [jsp/Forms], template might not exist or might not be accessible by any of the configured Template Resolvers
org.thymeleaf.exceptions.TemplateInputException: Error resolving template [Forms], template might not exist or might not be accessible by any of the configured Template Resolvers
at org.thymeleaf.engine.TemplateManager.resolveTemplate(TemplateManager.java:869) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:607) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
============================================= < / p>
我尝试了不同的解决方案。我的代码和指南中的代码没有任何区别。
要运行该表单,请使用以下两个链接:
http://本地主机:8080 / FlightDTO
http://本地主机:8080 / flight-radar / FlightDTO
请帮助:)