How to use TypeHandler for INSERT statements in MyBatis

There is a configuration:

<resultMap id="mapId" type="package.MyType">
    <result property="prop1" column="column1" />
    <result property="prop2" column="column2" />
    <result property="prop3" column="column3" typeHandler="package.MyTypeHandler" />
</resultMap>

<select id="selectStat" resultMap="mapId">
    SELECT `column1`, `column2`, `column3` 
    FROM `table`; 
</select>

For the select statement, everything is fine, the handler is called.

How can I write an INSERT statement to call the same handler for column3 when inserting data?

+4
source share
1 answer

You can use the INSERT statement as follows.

<insert parameterType='myType' >
  INSERT into table(column1, column2, column3) values(#{prop1},#{prop2},#{prop3,typeHandler=package.Typehandler})
</insert>

Edit : use typeHandler=, nottypeHandler=

+7
source

All Articles