2017-04-19 82 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

相關問題