亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Mybatis查詢條件包含List的情況說(shuō)明

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

查詢條件包含List的情況

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

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

在mybatis中查詢的語(yǔ)句

<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”)一致,

而不是只有一個(gè)list參數(shù)時(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

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

相關(guān)文章

最新評(píng)論