MyBatis框架使用问题

Mybatis根据数组或者List查询List结果

数组参数

//接口方法
ArrayList<User> selectByIds(Integer [] ids);
//xml映射文件
<select id="selectByIds" resultMap="BaseResultMap">
    select
    *
    from user where id in
    <foreach item="item" collection="array" open="(" separator="," close=")">
        #{item}
    </foreach>
</select>

List参数

//接口方法
ArrayList<User> selectByIds(List<Integer> ids);
//xml映射文件
<select id="selectByIds" resultMap="BaseResultMap">
    select  
    <include refid="Base_Column_List" />
    from user where id in
    <foreach item="item" index="index" collection="list" open="(" separator="," close=")">
        #{item}
    </foreach>
</select>

 

posted on 2023-07-15 15:38  王景迁  阅读(3)  评论(0编辑  收藏  举报

导航