2013-01-15 22 views
6

進出口使用spring,hibernate的,JAVA和JSP。我的問題是,當整數值爲零時,它會在我的文本框中顯示0。我想只顯示空字符串,但Idk如何做到這一點。請幫忙。Spring MVC的 - 如何顯示空白文本框時整數值爲零

在我的jsp:

<form:form method="POST" commandName="division"> 
... 
... 
    <form:input path="number"/> 
</form:form> 

在我的域名:

/** 
* Get the number of the division. 
* @return The number. 
*/ 
@Column(name = "NUMBER") 
public int getNumber() { 
    return number; 
} 

/** 
* Set the number of the division. 
* @param number The division number. 
*/ 
public void setNumber(int number) { 
    this.number = number; 
} 
+0

你能告訴我們你的JSP代碼和相關的servlet代碼?這是不可能回答這些類型的問題都沒有檢查代碼。 – Renjith

+1

使得'Integer'類型的屬性不是'int'。當你試圖將一個原始'int'值將autobox /拆箱它,你將有空當屬性沒有值,直到明確讓它0。 – Rizstien

回答

5

你將不得不使用spring:bind了點。

此外,你將不得不使用JSTL 。與導入:

<%@ taglib prefix="core" uri="http://java.sun.com/jsp/jstl/core"%> 

爲了獲得價值number

<spring:bind path="number"> 

spring:bind的結果返回在一個名爲status變量,在其value領域。檢查是否是0和打印什麼,否則打印數:

<core:if test="${status.value != 0}"> 
    ${status.value}  
</core:if> 

欲瞭解更多信息,請看看spring:bind documentation

相關問題