简体   繁体   中英

How to use TypeHandler for INSERT statements in MyBatis

There is 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 select statement all is fine, handler is invoked.

How can i write INSERT statement to invoke the same handler for column3 when inserting data?

You can use INSERT statement as follows.

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

Edit : use typeHandler= and not typehandler=

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM