• set


    set标签用于更新语句,当同事要更新多个字段时,我们需要留意当前是否是最后一个set,避免在后面出现,符号,使用set标签后可自动去除最后的逗号

    mapper:

    <update id="updateProductTest" parameterType="products"> update products <set> <if test="pname != null and pname != ''"> pname = #{pname}, </if> <if test="price != null and price > 0"> price = #{price}, </if> <if test="pdate != null"> pdate = #{pdate}, </if> <if test="cid != null and cid != ''"> cid = #{cid}, </if> </set> where pid = #{pid} </update>

    测试代码:

    @Test public void updateTest2(){ SqlSession session = factory.openSession(); ProductsMapper mapper = session.getMapper(ProductsMapper.class); //获取已有对象 Products product = mapper.selectProductById(7); product.setPname("云南小土豆"); product.setPrice(10.5f); //执行更新 mapper.updateProductTest(product); System.out.println(product); session.commit(); session.close(); }

     

  • 相关阅读:
    php7安装Memcached扩展
    php7安装
    结束进程
    openssl 编译
    boost 编译
    php 与 c++ openssl 加密通信
    iptables 端口转发
    获取进程及父进程的两种方式
    windows 下获取父进程pid
    CentOS 64位系统 yum安装32位软件包的方法
  • 原文地址:https://www.cnblogs.com/huaobin/p/14162722.html
Copyright © 2020-2023  润新知