org.apache.commons.beanutils.ConversionException: No value specified solutions

Transfer: https://www.cnblogs.com/linjiqin/archive/2011/07/21/2112628.html

When used in a java.sql.Date time and other non-built-in object, if the object is null This exception occurs. The easiest way is to ensure that non-built-in object is not null.

        

With the changes in demand and changes in project business, does not guarantee the built-in object is not null, it is necessary to solve this anomaly, in order to achieve a common effect, the following solution for this purpose abnormalities

Copy the code
      / ** Availability * / 
  Private java.sql.Date timeToMarket;
    // null when the attribute is timeToMarket is thrown org.apache.commons.beanutils.ConversionException: No value specified exception 
// public getTimeToMarket a Date () {
// return timeToMarket;
//}
//
// public void setTimeToMarket (a Date timeToMarket) {
// this.timeToMarket = timeToMarket;
//}


//解决办法
public String getTimeToMarket() {
if (timeToMarket == null) return null;
DateFormat dateFormat = DateFormat.getDateInstance();
return dateFormat.format(this.timeToMarket);
}

public void setTimeToMarket(String timeToMarket) {
if (timeToMarket == null || "".equals(timeToMarket.trim())) {
this.timeToMarket = null;
} else {
try {
DateFormat dateFormat = DateFormat.getDateInstance();
this.timeToMarket = new java.sql.Date(dateFormat.parse(
timeToMarket).getTime());
} catch (ParseException e) {
e.printStackTrace ();
}
}
}
Copy the code

Guess you like

Origin www.cnblogs.com/sharpest/p/11406779.html