美文网首页
MyBatis遇到的坑

MyBatis遇到的坑

作者: SmileMylife | 来源:发表于2019-08-06 21:20 被阅读0次

1.使用mybatis中的mapper文件中的resultType中设置的是list中的类型,而不是如果返回多个resultType为list。

2.当参数传递类型为list类型时,需要将parameterType设置为list,在xml中如果需要遍历,则collection需要填写成入参的名称或者在入参时加上@param注解声明传入的参数名,然后进行遍历。如下:

public void testMybatis(@Param("gaile") List<Map<String,Object>> list);
image.gif
<update id="testMybatis" parameterType="list">
    <foreach collection="gaile" item="param" separator=";">
        UPDATE ${param.user}
        <set>
            <if test="param.username != null and param.username != ''">
                username = #{param.username},
            </if>
            <if test="param.password != null and param.password != ''">
                password = #{param.password}
            </if>
        </set>
        WHERE id = #{param.id}
    </foreach>
</update>
image.gif

相关文章

网友评论

      本文标题:MyBatis遇到的坑

      本文链接:https://www.haomeiwen.com/subject/zmdgdctx.html