我正在尝试使用spring form执行更新操作。我的实体中很少有字段没有绑定在弹簧形式上(日期字段:createdDate,modifiedDate)。但是当我提交表单时,控制器上的日期字段变为空。我尝试过使用form:hidden field但是在提交表单时也没有保留datefields。请帮忙 这是我的实体
@Entity
@Table(name = "PORTAL_SUPPLIER")
public class PortalSupplier extends AbstractEntity implements Serializable {
/**
*
*/
private static final long serialVersionUID = 2187090408756348981L;
@Id
@Column(name = "SUPP_ID")
@TableGenerator(table = "PORTAL_TABLE_GENERATOR", name = "TABLE_SEQ_GENERATOR", pkColumnValue = "SUPP_ID",allocationSize = 1, initialValue = 1)
@GeneratedValue(strategy = GenerationType.TABLE, generator = "TABLE_SEQ_GENERATOR")
private int supplierId;
@Column(name = "TIN_NUM", nullable = true, length = 100)
private String tinNumber;
@Column(name = "SUPP_NAME", nullable = false, length = 200)
private String supplierName;
@Column(name = "SUPP_ADDRESS", nullable = true, length = 500)
private String supplierAddress;
@Column(name = "SUPP_EMAIL_ID", nullable = true, length = 100)
private String supplierEmailId;
@Column(name = "SUPP_PHONE_NUM", nullable = true, length = 20)
private String supplierPhoneNumber;
@Column(name = "SUPP_MOBILE_NUM", nullable = true, length = 20)
private String supplierMobileNumber;
@Column(name = "SUPP_ACTIVE_FLAG", nullable = false, length = 1)
private String supplierActive;
@Column(name = "MONTH", nullable = false, length = 2)
private int month;
@Column(name = "YEAR", nullable = false, length = 4)
private int year;
/**
* @return the supplierId
*/
public int getSupplierId() {
return supplierId;
}
/**
* @param supplierId the supplierId to set
*/
public void setSupplierId(int supplierId) {
this.supplierId = supplierId;
}
/**
* @return the tinNumber
*/
public String getTinNumber() {
return tinNumber;
}
/**
* @param tinNumber the tinNumber to set
*/
public void setTinNumber(String tinNumber) {
this.tinNumber = tinNumber;
}
/**
* @return the supplierName
*/
public String getSupplierName() {
return supplierName;
}
/**
* @param supplierName the supplierName to set
*/
public void setSupplierName(String supplierName) {
this.supplierName = supplierName;
}
/**
* @return the supplierAddress
*/
public String getSupplierAddress() {
return supplierAddress;
}
/**
* @param supplierAddress the supplierAddress to set
*/
public void setSupplierAddress(String supplierAddress) {
this.supplierAddress = supplierAddress;
}
/**
* @return the supplierEmailId
*/
public String getSupplierEmailId() {
return supplierEmailId;
}
/**
* @param supplierEmailId the supplierEmailId to set
*/
public void setSupplierEmailId(String supplierEmailId) {
this.supplierEmailId = supplierEmailId;
}
/**
* @return the supplierPhoneNumber
*/
public String getSupplierPhoneNumber() {
return supplierPhoneNumber;
}
/**
* @param supplierPhoneNumber the supplierPhoneNumber to set
*/
public void setSupplierPhoneNumber(String supplierPhoneNumber) {
this.supplierPhoneNumber = supplierPhoneNumber;
}
/**
* @return the supplierMobileNumber
*/
public String getSupplierMobileNumber() {
return supplierMobileNumber;
}
/**
* @param supplierMobileNumber the supplierMobileNumber to set
*/
public void setSupplierMobileNumber(String supplierMobileNumber) {
this.supplierMobileNumber = supplierMobileNumber;
}
/**
* @return the supplierActive
*/
public String getSupplierActive() {
return supplierActive;
}
/**
* @param supplierActive the supplierActive to set
*/
public void setSupplierActive(String supplierActive) {
this.supplierActive = supplierActive;
}
/**
* @return the month
*/
public int getMonth() {
return month;
}
/**
* @param month the month to set
*/
public void setMonth(int month) {
this.month = month;
}
/**
* @return the year
*/
public int getYear() {
return year;
}
/**
* @param year the year to set
*/
public void setYear(int year) {
this.year = year;
}
}
这是我的abstractbaseentity
@MappedSuperclass
public abstract class AbstractEntity {
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "DATE_CREATED", nullable = false)
private Date dateCreated;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "DATE_MODIFIED", nullable =false)
private Date dateModified;
@PrePersist
@PreUpdate
private void updateDate(){
dateModified = new Date();
}
/**
* @return the dateCreated
*/
public Date getDateCreated() {
return dateCreated;
}
/**
* @param dateCreated the dateCreated to set
*/
public void setDateCreated(Date dateCreated) {
this.dateCreated = dateCreated;
}
/**
* @return the dateModified
*/
public Date getDateModified() {
return dateModified;
}
/**
* @param dateModified the dateModified to set
*/
public void setDateModified(Date dateModified) {
this.dateModified = dateModified;
}
}
这是我的编辑表格
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Add Supplier</title>
</head>
<body>
<form:form method="post" modelAttribute="supplier" id="addSupplierForm">
<table border="0">
<tr>
<td><form:label path="tinNumber">TIN NUMBER</form:label></td>
<td><form:input path="tinNumber" /></td>
</tr>
<tr>
<td><form:label path="supplierName">SUPPLIER NAME</form:label></td>
<td><form:input path="supplierName" /></td>
</tr>
<tr>
<td><form:label path="supplierAddress">SUPPLIER ADDRESS</form:label></td>
<td><form:input path="supplierAddress" /></td>
</tr>
<tr>
<td><form:label path="supplierEmailId">SUPPLIER EMAIL ID</form:label></td>
<td><form:input path="supplierEmailId" /></td>
</tr>
<tr>
<td><form:label path="supplierPhoneNumber">SUPPLIER PHONE NUMBER</form:label></td>
<td><form:input path="supplierPhoneNumber" /></td>
</tr>
<tr>
<td><form:label path="supplierMobileNumber">SUPPLIER MOBILE NUMBER</form:label></td>
<td><form:input path="supplierMobileNumber" /></td>
</tr>
<tr>
<td><form:label path="month">MONTH</form:label></td>
<td><form:input path="month" /></td>
</tr>
<tr>
<td><form:label path="year">YEAR</form:label></td>
<td><form:input path="year" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="SUBMIT"></td>
</tr>
<tr>
<td><form:hidden path="supplierActive"/></td>
<td><form:hidden path="dateCreated"/></td>
<td><form:hidden path="dateModified"/></td>
</tr>
</table>
</form:form>
</body>
</html>