我尝试在GetTodoController中实现TodoList编辑,但它不起作用。
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Create Todo</title>
<link rel="stylesheet" th:href="@{/styles/todo/operation.css}">
</head>
<body>
<h2>Edit your Todo!</h2>
<form th:method="PUT" th:action="@{/todo/edit/{id}(id=${list.id})}" th:object="${list}">
<label for="name">Name: </label>
<input type="text" th:field="*{name}" id="name">
<span style="color: #ba6a65" th:if="${#fields.hasErrors('name')}" th:errors="*{name}"></span>
<br>
<label for="description">Description: </label>
<textarea th:field="*{description}" id="description">Enter text here...</textarea>
<span style="color: #ba6a65" th:if="${#fields.hasErrors('description')}" th:errors="*{description}"></span>
<br>
<label for="deadline">Deadline: </label>
<input type="datetime-local" th:field="*{deadline}" id="deadline">
<span style="color: #ba6a65" th:if="${#fields.hasErrors('deadline')}" th:errors="*{description}"></span>
<br>
<input type="submit">
</form>
</body>
</html>
个字符
我已经将@PutMapping更改为@PostMapping,将th:method=“PUT”更改为th:method=“POST”,一切都正常工作,但它在概念上是错误的,因为@PostMapping -添加新的,@PutMapping -更新
1条答案
按热度按时间wwwo4jvm1#
为了使PUTMap与Sping Boot 和Thymeleaf一起工作,您需要在application.properties中设置以下属性:
字符串
这将启用隐藏方法过滤器,当与th:方法一起使用时,过滤器将允许正确处理PUT方法。