最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Mybatis查詢條件包含List的情況說明

 更新時間:2021年09月23日 16:37:55   作者:高中華  
這篇文章主要介紹了Mybatis 查詢條件包含List的情況,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

查詢條件包含List的情況

在mybatis中進(jìn)行搜索時,有時候參數(shù)中包含了List,比如傳入?yún)?shù):

public class FileRequest{
    //文件類型
    private Integer fileType;
    //狀態(tài)
    private List<Status> statusList;
} 
public class Status{
    //注冊狀態(tài)
    private Integer registerStatus;
    //會議狀態(tài)
    private Integer meetingStatus
}

在mybatis中查詢的語句

<select id="findList" parameterType="FileRequest" resultMap="...">
    select * from tableName where
    1=1
    <if test="fileType != null ">
        and file_type = #{fileType}
    </if>
    <if test="statusList != null ">
        and 
        <foreach collection="statusList" index="index" item="item" open"(" separator="or" close=")">
            <if test="item.registerStatus != null ">
                and register_status= #{item.registerStatus}
            </if>
            <if test="item.meetingStatus != null ">
                and meeting_status= #{item.meetingStatus }
            </if>    
        </foreach>
    </if>
</select>

查詢條件帶List和其他類型字段

需求

Mybatis查詢條件帶List和其他類型字段(Integer,String,...).

select * from table where type=?
and code in (?,?,?,?)

Mapper.java文件

List<BaseDictionary> selectByTypeAndCodes(
 @Param("codes") List<Integer> codes,
@Param("type") Integer type);
 Mapper.xml.

注意其中<foreach collection="codes"中的collection的值要和你定義的List別名@Param(“codes”)一致,

而不是只有一個list參數(shù)時的<foreach collection="list"

<select id="selectByTypeAndCodes"  resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from base_dictionary
    where type = #{type}
    AND code in
    <foreach collection="codes" index="index" item="item" open="(" separator="," close=")">
     #{item}
    </foreach>
    AND show_enable=1
    AND obj_status=1
    ORDER BY sort
  </select>

執(zhí)行結(jié)果:

BaseJdbcLogger.debug(BaseJdbcLogger.java:145)==> Preparing: select id, type, name, code, sort, show_enable, obj_remark, obj_status, obj_createdate, obj_createuser, obj_modifydate, obj_modifyuser from base_dictionary where type = ? AND code in ( ? , ? , ? ) AND show_enable=1 AND obj_status=1 ORDER BY sort

BaseJdbcLogger.debug(BaseJdbcLogger.java:145)==> Parameters: 34(Integer), 1(Integer), 2(Integer), 3(Integer)

BaseJdbcLogger.debug(BaseJdbcLogger.java:145)<== Total: 2

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

措勤县| 紫云| 渑池县| 宝清县| 临汾市| 襄城县| 印江| 邹平县| 凉山| 岫岩| 隆昌县| 安国市| 隆昌县| 宝山区| 井陉县| 甘德县| 汝阳县| 和林格尔县| 濮阳县| 海阳市| 琼海市| 永新县| 广河县| 来安县| 巴中市| 南木林县| 台中市| 扬州市| 潮州市| 台北市| 芮城县| 星座| 克山县| 得荣县| 敖汉旗| 常熟市| 叙永县| 丘北县| 额敏县| 罗江县| 铁力市|