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