欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Mybatis和orcale update语句中接收参数为对象的实例代码

程序员文章站 2024-02-28 10:48:58
mybatis的 mapper.xml 中 update 语句使用 if 标签判断对像属性是否为空值。   userdto是传过来参数的类型,userdto是在...

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>

总结

以上所述是小编给大家介绍的mybatis和orcale update语句中接收参数为对象的实例代码,希望对大家有所帮助