繁体   English   中英

执行处理器 'org.thymeleaf.spring5.processor.SpringOptionFieldTagProcessor' 期间出错

[英]Error during execution of processor 'org.thymeleaf.spring5.processor.SpringOptionFieldTagProcessor'

我经常遇到下面列出的错误。

模型应该为表单提供 3 List<Food/Drink/Trick> 每个 Food,Drink,Trick 作为一个单独的类。 它是从数据库中获取的并且可以工作。

视图应列出每个 Food、Drink、Trick 属性名称的名称。

食物和饮料是单选的。 技巧是多选。 无论选择什么,都应该传递到 Created 对象上。

我的问题是 th:field="*{tricks}"。

非常感谢您的回复。

  public String createNewFoxGet(Model model, @RequestParam(required = false) String name) {

    if (name == null) {
      name = "";
    }

    model.addAttribute("fox", new Fox());

    model.addAttribute("tricksAll", trickService.getAllTrickTypes());
    model.addAttribute("drinkAll", drinkService.getAllDrinkTypes());
    model.addAttribute("foodAll", foodService.getAllFoodTypes());
    model.addAttribute("name", name);

    return "createnewfox";
  }
-----------------
<form action="#" th:action="@{/createnewfox}" th:object="${fox}" method="post">
  <p>New Fox</p>
<div class="form-group-name">
  <label for="name">Name:</label>
  <input type="text" name="name" id="name" placeholder="match with signup name" th:field="*{name}" minlength="2">
</div>

  <label for="favouriteFood">Favourite food:</label>
  <select name="favouriteFood" id="favouriteFood">
    <option th:each="element:${foodAll}" th:value="${element}" th:field="*{food}"
            th:text="${element.getName()}"></option>
  </select>

  <label for="favouriteDrink">Favourite drink:</label>
  <select name="favouriteDrink" id="favouriteDrink">
    <option th:each="element:${drinkAll}" th:value="${element}" th:field="*{drink}"
            th:text="${element.getName()}"></option>
  </select>
  <br>

  <label for="foxTricks">Fox tricks:</label>
  <select name="foxTricks" id="foxTricks" multiple>
    <option th:each="element:${tricksAll}" th:value="${element}" th:field="*{tricks}"
            th:text="${element.getName()}"></option>
  </select>
  <br>

  <p>Hold down the Ctrl (windows) / Command (Mac) button to select multiple tricks.</p>
  <br>

  <button type="submit" class="btn btn-primary">GO!</button>

</form>
-----------------------------

An error happened during template parsing (template: "class path resource [templates/createnewfox.html]")
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/createnewfox.html]")

Caused by: org.attoparser.ParseException: Error during execution of processor 'org.thymeleaf.spring5.processor.SpringOptionFieldTagProcessor' (template: "createnewfox" - line 47, col 69)
    at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:393)
    at org.attoparser.MarkupParser.parse(MarkupParser.java:257)
    at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:230)
    ... 48 more
Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Error during execution of processor 'org.thymeleaf.spring5.processor.SpringOptionFieldTagProcessor' (template: "createnewfox" - line 47, col 69)

Caused by: org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.lang.Long] for value 'Trick(id=1'; nested exception is java.lang.NumberFormatException: For input string: "Trick(id=1"```

这个就解决了。 问题是 select 中的 name="foxTricks" 与实际的对象属性名称不匹配。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM