mybatis 多个条件in查询
1. UI如下, 共有四个查询条件,每个查询可以多选,所以考虑用in查询
2. 查询DTO类封装如下:
@Data
@ApiModel(value = "整机下市明细信息查询对象")
public class MachineOffMarketQueryDto {
@ApiModelProperty(value = "型号编码集合", required = true)
@NotEmpty(message="型号编码集合不能为空")
private List<String> productCodes;
@ApiModelProperty(value = "型号名称集合", required = true)
@NotEmpty(message="型号名称集合不能为空")
private List<String> productNames;
@ApiModelProperty(value = "PLC状态集合", required = true)
@NotEmpty(message="PLC状态集合不能为空")
private List<String> plcStates;
@ApiModelProperty(value = "PLC状态实际日期集合", required = true)
@NotEmpty(message="PLC状态实际日期集合不能为空")
private List<String> dateActuals;
@ApiModelProperty(value = "查询页码", required = true)
@NotNull(message="查询页码不能为空")
private Integer pageNumber;
@ApiModelProperty(value = "查询页size", required = true)
@NotNull(message="查询页码大小不能为空")
private Integer pageSize;
public String toString(){
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("productCodes", getProductCodes())
.append("productNames", getProductNames())
.append("plcStates", getPlcStates())
.append("dateActuals", getDateActuals())
.append("pageNumber", getPageNumber())
.append("pageSize", getPageSize())
.toString();
}
}
3. Controller
4. service:
4. Mapper.xml
<select id="selectMachineOffMarketInfo" parameterType="MachineOffMarketQueryDto" resultType="DiOffMarketModelDetailDo">
SELECT product_code, product_name, sub_pl_code, sub_pl_name, industry, prod_life_state, date_plan, date_actual, src_etl_date, trg_etl_date,
pt, product_place, offline_number, creator, create_time, update_time
from di_off_market_model_detail
where 1='1'
<if test="productCodes != null and productCodes.size() >0">
and product_code in
<foreach collection="productCodes" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</if>
<if test="productNames != null and productNames.size() >0">
and product_name in
<foreach collection="productNames" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</if>
<if test="plcStates != null and plcStates.size() >0">
and prod_life_state in
<foreach collection="plcStates" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</if>
<if test="dateActuals != null and dateActuals.size() >0">
and date_actual in
<foreach collection="dateActuals" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</if>
</select>
标签:
mybtais
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?