zoukankan      html  css  js  c++  java
  • Mybatis 向statement传入多个参数

    1、一般情况下可以将多个参数放入Map,让Map作为statement的参数

    public void update(@Param("fieldMap") Map<String, Object> fields);
        <update id="update" parameterType="Map">
            UPDATE <include refid="table" />
            SET
                <foreach item="value" index="key" collection="fieldMap" separator=",">
                    ${key} = #{value}
                </foreach>
            WHERE
                id = #{map.id}
        </update>

    Map的缺点是里面的Key值只有到了运行期才知道,而且无法处理类似一个Integer,一个List<Integer>的情况

    如果专门写个Pojo的话,这个Pojo的复用性可能不好,容易定义大量的类。

    2、另一个方法是在statement的接口方法声明中,设计多个参数。

    public void set(@Param("name") String nameStr, @Param("ids") List<DepartmentPo> pos);
    <!-- 注意这里不再需要parameterType属性了 -->
    <insert id="set">
        UPDATE <include refid="table" />
        SET name = #{name}
        WHERE id IN
        <foreach collection="pos" item="po" open="(" separator="," close=")">
            #{po.id}
        </foreach>
    </insert>
  • 相关阅读:
    高斯消元
    逻辑运算符之优先级&&and、or
    康托展开
    关于bootstrap的双层遮罩问题
    写好页面在内网内访问
    swiper插件的一些坑
    第一篇博客
    poj 3415 Common Substrings
    poj 1509 Glass Beads
    poj 3260 The Fewest Coins
  • 原文地址:https://www.cnblogs.com/deolin/p/7411617.html
Copyright © 2011-2022 走看看