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>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM