When non-built-in objects such as java. SQL. Date are used, this exception occurs if the object is null. The simplest method is to ensure that non-built-in objects are not null.
As the demand changes in the project business, there is no guarantee that the built-in objects are not null. Therefore, it is necessary to solve this exception to achieve a general effect. The following is a solution to this exception:
/** Time to market */
Private java. SQL. Date timeToMarket;
// If timeToMarket is null, The org. apache. commons. beanutils. ConversionException: No value specified exception is thrown.
// Public Date getTimeToMarket (){
// Return timeToMarket;
//}
//
// Public void setTimeToMarket (Date timeToMarket ){
// This. timeToMarket = timeToMarket;
//}
// Solution
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 ();
}
}
}