您的位置:首页 > 编程语言

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

2017-09-06 15:17 507 查看

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语句中接收参数为对象的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!

您可能感兴趣的文章:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mybatis orcale update