Specify typeHandler for List<T> in mybatis.
typeHandler | java type | sql type |
---|---|---|
ListStringHandler | List<String> | varchar[] |
ListBigDecimalHandler | List<BigDecimal> | numeric[] |
ListBooleanHandler | List<Boolean> | bool[] |
ListDateHandler | List<Date> | date[] |
ListIntegerHandler | List<Integer> | integer[] |
pom.xml
<dependency>
<groupId>io.github.gaojizhou</groupId>
<artifactId>MybatisTypeHandler</artifactId>
<version>1.0.1</version>
</dependency>
Mybatis xml file
<select id="queryDog" resultMap="ResultMap">
select id, name, coat_colors from dog
where dog.id = any(#{ids,jdbcType=ARRAY,typeHandler=io.github.gaojizhou.ListStringHandler})
</select>
<resultMap id="ResultMap" type="io.github.gaojizhou.xxxxx.Dog">
<id column="id" jdbcType="VARCHAR" property="id"/>
<result column="name" jdbcType="VARCHAR" property="name"/>
<result column="coat_colors"
jdbcType="ARRAY"
property="coatColors"
typeHandler="io.github.gaojizhou.ListStringHandler"/>
</resultMap>
See the LICENSE file for license rights and limitations (GPL-3.0 or later).