Mybatis&orcale update语句中接收参数为对象

 Mybatis的 mapper.xml 中 update 语句使用 if 标签判断对像属性是否为空值。

 

  UserDTO是传过来参数的类型,userDTO是在mapperDao接口中给更新方法的参数起的别名。

   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>

原文地址:https://www.cnblogs.com/gczmn/p/7481696.html