1

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

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>
4

0 回答 0