购物网站28:类型转换器---日期----配送方式----性别----订单状态----支付方式----性别----系统权限

public class DateConverter implements Converter {

 @SuppressWarnings("unchecked")
 public Object convert(Class clazz, Object value) {
  if(value==null || "".equals((String)value)) return null;
  if(value instanceof Date) return value;
  DateFormat convert = new SimpleDateFormat("yyyy-MM-dd");
  try {
   return convert.parse((String) value);
  } catch (ParseException e) {
   DateFormat convert2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
   try {
    return convert2.parse((String) value);
   } catch (ParseException e1) {}
  }
  return null;
 }

}

 

-----------------------------------------------------------------

 

public class DeliverWayConverter implements Converter {
 
 @SuppressWarnings("unchecked")
 public Object convert(Class clazz, Object value) {//request.getParameter("")
  if(value==null || "".equals((String)value)) return null;
  if(value instanceof DeliverWay) return value;
  try{
   return DeliverWay.valueOf((String) value);
  }catch (Exception e) {}
  return null;
 }

}

 

-------------------------------------------------------------------

 

public class GenderConverter implements Converter {
 
 @SuppressWarnings("unchecked")
 public Object convert(Class clazz, Object value) {//request.getParameter("")
  if(value==null || "".equals((String)value)) return null;
  if(value instanceof Gender) return value;
  try{
   return Gender.valueOf((String) value);
  }catch (Exception e) {}
  return null;
 }
}

 

----------------------------------------------------------------

 

public class OrderStateConverter implements Converter {
 
 @SuppressWarnings("unchecked")
 public Object convert(Class clazz, Object value) {//request.getParameter("")
  if(value==null || "".equals((String)value)) return null;
  if(value instanceof OrderState) return value;
  try{
   return OrderState.valueOf((String) value);
  }catch (Exception e) {}
  return null;
 }

}

 

--------------------------------------------------------------------

 

public class PaymentWayConverter implements Converter {
 
 @SuppressWarnings("unchecked")
 public Object convert(Class clazz, Object value) {//request.getParameter("")
  if(value==null || "".equals((String)value)) return null;
  if(value instanceof PaymentWay) return value;
  try{
   return PaymentWay.valueOf((String) value);
  }catch (Exception e) {}
  return null;
 }

}

 

---------------------------------------------------------------------------

 


public class SexConverter implements Converter {

 @SuppressWarnings("unchecked")
 public Object convert(Class clazz, Object value) {
  if(value==null || "".equals((String)value)) return null;
  if(value instanceof Sex) return value;
  try{
   return Sex.valueOf((String) value);
  }catch (Exception e) {}
  return null;
 }

}

 

-----------------------------------------------------------------------

 

public class SystemPrivilegePKConverter implements Converter {
 
 @SuppressWarnings("unchecked")
 public Object convert(Class clazz, Object value) {//request.getParameter("")
  if(value==null || "".equals((String)value)) return null;
  if(value instanceof SystemPrivilegePK) return value;
  try{
   String[] arr = ((String) value).split(",");
   return new SystemPrivilegePK(arr[0], arr[1]);
  }catch (Exception e) {}
  return null;
 }


}

你可能感兴趣的:(string,object,exception,class,null,date)