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

     

  • 相关阅读:
    poj 2155 B
    hdu 1556 A
    hdu 1556 A
    #366 A-C
    最长上升子序列
    Codeforces Div3 #501 A-E(2) F以后补
    字典的建立 查找
    字典序大小
    头文件模板
    01背包模板 及 优化
  • 原文地址:https://www.cnblogs.com/huaobin/p/14162722.html
Copyright © 2011-2022 走看看