看啦这么就别人的博客 我也来写一篇! Object转换其他类型

package com.sinitek.framework.util;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.Date; /**
* Created by IntelliJ IDEA.
* User: Administrator
* Date: 2011-5-23
* Time: 16:09:26
* To change this template use File | Settings | File Templates.
*/
public class JdbcQueryUtils
{
/**
* 转Double
* @param object
* @return
*/
public static Double convertToDouble( Object object )
{
if ( object == null )
return null ; if ( object instanceof BigDecimal )
{
return ( ( BigDecimal )object ).doubleValue( ) ;
} return null ;
} /**
* 转String
* @param object
* @return
*/
public static String convertToString( Object object )
{
if ( object == null )
return null ; if ( object instanceof String )
{
return object.toString( ) ;
} else {
return String.valueOf(object);
} } /**
* 转Integer
* @param object
* @return
*/
public static Integer convertToInteger( Object object )
{
if ( object == null )
return null ; if ( object instanceof BigDecimal )
{
return ( ( BigDecimal )object ).intValue( ) ;
} return null ;
} /**
* 转Date
* @param object
* @return
*/
public static Date convertToDate( Object object )
{
if ( object == null )
return null ; if ( object instanceof Timestamp )
{
return new Date( ( ( Timestamp )object ).getTime( ) ) ;
} return null ;
}
}
上一篇:酷炫地给py代码标上行数


下一篇:重拾C,一天一点点_10