首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >java.lang.NumberFormatException:输入字符串:"com.connectors.entity.Templates@156d878f“

java.lang.NumberFormatException:输入字符串:"com.connectors.entity.Templates@156d878f“
EN

Stack Overflow用户
提问于 2017-04-19 19:33:03
回答 1查看 1.7K关注 0票数 1

我从某个时间点开始使用Thymeleaf,并且我多次遇到这个问题。

当我使用Spring Boot添加动态行时出现以下错误:

java.lang.NumberFormatException:对于输入字符串:"com.connectors.entity.Templates@156d878f“

当GET request方法时,这可以很好地工作,但是当我从post方法重定向时,我得到了上面的异常。

HTML代码:

代码语言:javascript
复制
<div class="col-sm-5">
  <select th:field="*{templates}" class="form-control" name="queueMGR" id="queueMGR">
    <!-- <option selected="selected" disabled="disabled" value="Choose...">Choose...</option> -->
    <option th:each="type : ${templatesList}" th:value="${type}" th:text="${type.name}"></option>
  </select>
</div>

Spring请求处理程序:

代码语言:javascript
复制
@RequestMapping(value = "/add", params = {"addRow"})
public String addRow(final AddIntegrations addIntegrations,
                     final BindingResult bindingResult, Model model) {

    addIntegrations.getHeaderProperties().add(new HeaderProperties());

    List<Templates> templatesList = new ArrayList<Templates>();
    Templates templates = new Templates();
    templates.setId(1);
    templates.setName("first template");
    templates.setContext("context");
    templatesList.add(templates);

    templates = new Templates();
    templates.setId(2);
    templates.setName("second template");
    templates.setContext("context");
    templatesList.add(templates);

    model.addAttribute("templatesList", templatesList);
}

现在,如果我添加了另一个select - option,并且如果我在modal中添加了另一个列表,那么它就可以正常工作。

仅在此select选项中遇到问题。在这里,我也得到了注释选项标签的错误。如下所示:

java.lang.NumberFormatException:对于输入字符串:"Choose...“

请给我引路。

提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2017-04-19 19:44:34

在调用${type}时,在值中调用类TemplatestoString()方法时,应该使用${type.id},如下所示:

代码语言:javascript
复制
<div class="col-sm-5">
    <select th:field="*{templates}" class="form-control" name="queueMGR" id="queueMGR">
          <!-- <option selected="selected" disabled="disabled" value="Choose...">Choose...</option> -->
         <option th:each="type : ${templatesList}" th:value="${type.id}" th:text="${type.name}"></option>
    </select>
</div>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43494548

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档