控制器
@GetMapping({"/create", "/create/"}) public String createGet(CorePhrasesCreateForm corePhrasesCreateForm) { return "semantics/phrases/core/create"; } @PostMapping({"/create", "/create/"}) public String createPost(@Valid CorePhrasesCreateForm corePhrasesCreateForm, BindingResult bindingResult, RedirectAttributes atts) { corePhraseFormValidator.validate(corePhrasesCreateForm, bindingResult); if (bindingResult.hasErrors()) { return "semantics/phrases/core/create"; } atts.addAttribute("message", "Core phrases created"); String result = ""; return "redirect:/general/message"; }
类型
<!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>Title</title> <link rel="stylesheet" type="text/css" href="/css/main.css"/> </head> <body> <a th:href="@{/admin/}">Admin</a> <br> <br> <h1>Add core phrases to the database</h1> <br> <br> <form method="POST" th:object="${corePhrasesCreateForm}"> <table> <tr> <td>Quotation cluster (" "):</td> <td><input type="number" name="quotationCluster" th:value="${quotationCluster}"/></td> <td th:if="${#fields.hasErrors('quotationCluster')}" th:errors="*{quotationCluster}">quotationCluster</td> </tr> <tr> <td>Quotation Exclamation cluster ("!")</td> <td><input type="number" name="quotationExclamationCluster" th:value="${quotationExclamationCluster}"/></td> <td th:if="${#fields.hasErrors('quotationExclamationCluster')}" th:errors="*{quotationExclamationCluster}"> quotationExclamationCluster </td> </tr> <tr> <td>Phrases</td> <td><textarea rows="5" cols="60" name="value" placeholder="Key phrases" th:text="${value}"></textarea></td> <td class="error" th:if="${#fields.hasErrors('value')}" th:errors="*{value}">value</td> </tr> </table> <br> <br> <br/> <input type="submit" value="submit"/> </form> </body> </html>
问题是:现在quotationCluster和quotationExcramationCluster默认发送0。也就是说,这两个字段为空,控制器将得到零。
但0是一个有意义的值。例如,一些DBMS可以从0开始其ID。因此,0是一个禁忌。
默认情况下,我需要-1。
你能帮我整理一下吗?