zoukankan      html  css  js  c++  java
  • 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>

  • 相关阅读:
    【bzoj1010】[HNOI2008]玩具装箱toy
    bzoj 3173
    bzoj 1179
    bzoj 2427
    bzoj 1051
    bzoj 1877
    bzoj 1066
    bzoj 2127
    bzoj 1412
    bzoj 3438
  • 原文地址:https://www.cnblogs.com/gczmn/p/7481696.html
Copyright © 2011-2022 走看看