Java tutorial
/** * Copyright (c) 2005-2012 springside.org.cn * * Licensed under the Apache License, Version 2.0 (the "License"); */ package org.exitsoft.common.utils; import java.util.Date; import org.apache.commons.beanutils.converters.DateConverter; /** * ? * * @author calvin * */ public class ConvertUtils extends org.apache.commons.beanutils.ConvertUtils { static { registerDateConverter("yyyy-MM-dd"); } /** * ?,??yyyy-MM-dd * * @param patterns ? */ public static void registerDateConverter(String... patterns) { DateConverter dc = new DateConverter(); dc.setUseLocaleFormat(true); dc.setPatterns(patterns); register(dc, Date.class); } /** * Apache BeanUtils?. * * @param value ?. * @param toType ?. */ public static Object convertToObject(String value, Class<?> toType) { try { return convert(value, toType); } catch (Exception e) { throw ReflectionUtils.convertReflectionExceptionToUnchecked(e); } } /** * ?. * * @param value ?. * @param toType ?. */ public static Object convertToObject(String[] values, Class<?> toType) { try { return convert(values, toType); } catch (Exception e) { throw ReflectionUtils.convertReflectionExceptionToUnchecked(e); } } }