I am doing a project that uses Spring 3.1.1 and MyBatis3.0.
I am trying to change iBatis to MyBatis. However, I am struggling with resultmap.
When using iBatis, I can process the values from the request, as shown below, using "nullValue".
<resultMap class="java.util.HashMap" id="ChannelData">
<result property="id" javaType="java.lang.String" column="CHANNEL_ID" nullValue=""/>
<result property="code" column="SELECTSCOPE" nullValue="Television"/>
</resultMap>
The problem is that there is no 'nullValue' in MyBatis. Also, if the column is "null", mybatis never populates this element. eg. if "SELECTSCOPE" is null, it brings {id=aaa}. I need such data → {id=aaa, code=''}. Is there any way to handle this?
PS
I request more than 20 columns. Some of them need "" when the value is null, others have their own default value for some string value. (If I use iBatis, "nullValue" is the magic keyword), I found some links that recommend using a custom type handler, but making the handler over 20 may cause future confusion for repair or maintenance. I need an easy way.
Thanks a lot: D
==================================================== ======================================
I found a way to bring some null values. It needs some configuration.
- make config.xml, which should contain some information about MyBatis Config DTD and settings, as shown below
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD SQL MAP Config 3.1//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<setting name="callSettersOnNulls" value="true"/>
</settings>
</configuration>
{id="aaa", code = null}. . ? . "code" null, String "default".
{id="aaa", code=null} {id="aaa",code="default"}. ?
~