Using mybatis to write SQL requires dynamic update of object data. The fields that need to be updated each time are different. In order to prevent null null exceptions, dynamic SQL is needed.
<update id="update" parameterType="com.commuli.po.User">update s_user<trim prefix="set" suffixOverrides=","><if test="name!=null">name=#{name},</if><if test="age!=null">age=#{age},</if><if test="address!=null">address=#{address},</if><if test="createDate!=null">createDate=#{createDate},</if></trim>whereid=#{id}</update>Note: The trim tag is used to remove the comma "," of the last field in SQL.
The above is the dynamic update data of using MyBatis introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!