Mybatis查询条件包含List的情况说明

网友投稿 1062 2022-12-06

Mybatis查询条件包含List的情况说明

Mybatis查询条件包含List的情况说明

目录查询条件包含List的情况在mybatis中查询的语句查询条件带List和其他类型字段需求

查询条件包含List的情况

在mybatis中进行搜索时,有时候参数中包含了List,比如传入参数:

public class FileRequest{

//文件类型

private Integer fileType;

//状态

private List statusList;

}

public class Status{

//注册状态

private Integer registerStatus;

//会议状态

private Integer meetingStatus

}

在mybatis中查询的语句

select * from tableName where

1=1

and file_type = #{fileType}

and

and register_status= #{item.registerStatus}

and meeting_status= #{item.meetingStatus }

查询条件带List和其他类型字段

需求

Mybatis查询条件带List和其他类型字段(Integer,String,...).

select * from table where type=?

and code in (?,?,?,?)

Mapper.java文件

List selectByTypeAndCodes(

@Param("codes") List codes,

@Param("type") Integer type);

Mapper.xml.

注意其中

而不是只有一个list参数时的

select

from base_dictionary

where type = #{type}

AND code in

#{item}

AND show_enable=1

AND obj_status=1

ORDER BY sort

执行结果:

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

而不是只有一个list参数时的

select

from base_dictionary

where type = #{type}

AND code in

#{item}

select

from base_dictionary

where type = #{type}

AND code in

#{item}

AND show_enable=1

AND obj_status=1

ORDER BY sort

执行结果:

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

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:mybatis @Intercepts的用法解读
下一篇:mybatis 集合嵌套查询和集合嵌套结果的区别说明
相关文章

 发表评论

暂时没有评论,来抢沙发吧~