用于多列映射的ibatis TypeHandlerCallback - Money对象

时间:2012-05-04 19:27:04

标签: orm callback ibatis

Ibatis多列数据映射到类型处理程序。 我有一个我正在使用的货币对象需要价值和货币。 如何将多个列映射到同一个callbacktype处理程序?

Java Money对象 http://www.javapractices.com/topic/TopicAction.do?Id=13

public class MoneyTypeHandlerCallBack implements TypeHandlerCallback {

//The below works but problems it always defaults currency. I need to be able to get     Currency as well to use
// new Money(value, currency ) constructor
@Override
public Object getResult(final ResultGetter getter) throws SQLException {
        BigDecimal value = getter.getBigDecimal();
    if (value == null) {
        return null;
    }
    Money result = new Money(value); // I need to be able to do new Money (value, currency)
    return result;
}
... implment other...
}   

SomeView Bean定义:

public class SomeView implements Serializable{

    private String companyName
    private Money netamount;

    // .....geters and setters etc
}

SQLMAP配置:

<sqlMap namespace="myspace">
<typeAlias alias="someView" type="com.my.view.someView" />
<resultMap id="some_detail_view" class="someView">
    <result property="companyName" column="COMPANY" />
    ...
    <result property="netamount" column="NET_AMT" />
    <result property="netamountCurrency" column="NET_AMT_CURRENCY" />
</resultMap>    
<select id="someView" parameterClass="java.util.Map" 
              resultClass="someView" resultMap="some_detail_view">
  SELECT COMPANY, NET_AMT, NET_AMT_CURRENCY From......
</select>
</sqlMap>

0 个答案:

没有答案