看啦这么就别人的博客 我也来写一篇! 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 ;
}
}

posted on 2016-03-15 16:37  zzz初见  阅读(332)  评论(0编辑  收藏  举报

导航