是否可以在POST
中分配PUT
或from th:action
方法,具体取决于th:if
?
类似的东西:
<form th:if="${firm.firmId} == null" th:action="@{~/firms/save}" method="POST" modelAttribute="firm" th:object="${firm}">
<form th:if="${firm.firmId} != null" th:action="@{~/firms/save}" method="PUT" modelAttribute="firm" th:object="${firm}">
答案 0 :(得分:4)
Thymeleaf有条件算子
condition ? first_expression : second_expression;
您可以将此运算符用于您的目的:
<form th:action="@{~/firms/save}" th:method="${firm.firmId} != null ? PUT : POST" modelAttribute="firm" th:object="${firm}">