2017-04-19 60 views
1

问候!!java.lang.NumberFormatException:对于输入字符串:“[email protected]”

我从某个时候开始使用百里香,我几次都面临这个问题。

我收到以下错误,当我添加动态行使用春季启动 - 百里香。

java.lang.NumberFormatException:对于输入字符串: “[email protected]

当GET请求方法这个完美的作品,但是当我从post方法重定向我我正在超越例外。

HTML代码:

<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> 

春天请求处理程序:

@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); 
} 

现在,如果我添加另一个选择 - 选项,并说,如果我在模态添加另一个列表,它工作正常。

只有这个选择选项的问题。在这里,我也收到了评论选项标签的错误。象下面这样:

java.lang.NumberFormatException:对于输入字符串: “选择...”

请指引我。

在此先感谢。

詹姆斯

回答

1

当你调用${type}你叫Templates类的toString()方法在你的价值,你应该使用${type.id} 事情是这样的:

<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> 
+0

嗨安杰洛, 感谢您的快速回复。但是当我们提交表单时,我需要传递整个对象。那么我需要做什么?我在这个下面写了另外两个下拉列表,它使用th:value:$ {type}。我只有这个问题。甚至为注释选项获得相同的错误。 – James

+0

如果你需要传递整个对象,你必须把它写在HTML页面/也许在隐藏的字段中)或者你必须创建一个JS对象来传递休息调用 –

+0

哦好吧。谢谢。现在我正在使用休息调用来提交对象..但问题仍然存在,为什么上面的代码不适用于特定的选择,它与其他选择相同的实现工作。奇怪。 – James

相关问题