Mybatis and orcale update statements receive instance code with arguments as objects

  • 2020-11-03 22:12:33
  • OfStack

The update statement in ES2en. xml of Mybatis USES the if tag to determine whether an image attribute is null.

UserDTO is the type of parameter passed in, and userDTO is the alias given to the parameter of the updated method in the mapperDao interface.

mapperDao.java


int updata(@Param("userDTO") UserDTO userDTO);

mapper.xml


<update id="updata" parameterType="UserDTO">
  UPDATE
    table u
  <set>
    <if test=" userDTO.age!=null and userDTO.age !='' ">
      u.identity = #{userDTO.age},
    </if>
    <if test=" userDTO.name !=null and userDTO.name !='' ">
      u.name = #{userDTO.name},
    </if>
   </set>
   <where>
      u.id = #{userDTO.id}
  </where>
</update>

conclusion


Related articles: