色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術文章
文章詳情頁

Mybatis中and和循環(huán)or混用操作(or轉換成in)

瀏覽:45日期:2023-10-18 16:45:28
Mybatis and和循環(huán)or混用

這次項目用到一個and和or混用的場景 , 因為用到多個or(循環(huán)), 沒想到好的辦法

最終轉換成用 IN實現:

場景

用left join鏈接多個表, 多個條件and篩選, 其中狀態(tài)(state)條件篩選出多個可選狀態(tài)的條目,

本來想用and 和 or 但是 or的條件是個數組參數, 需要遍歷states , 可能0個可能多個, 拼了半天沒有成功 , 最后發(fā)現用 IN 和FOREACH就可以了

DAO層接口

List<OrderInfoForm> selectOrdersByStatesSelective( @Param(value='order')Order order, @Param(value='states')Integer[] states);Mybatis實現

<select resultMap='AllResultMap' > select <include refid='All_Column_List' /> from order_list LEFT JOIN product_method ON product_method.`code` = order_list.purchase_method LEFT JOIN product_color ON product_color.`code` = order_list.color LEFT JOIN product_guarantee ON product_guarantee.`code` = order_list.guarantee LEFT JOIN product_info ON order_list.product_id = product_info.id LEFT JOIN product_model ON product_info.model = product_model.`code` LEFT JOIN product_standard ON product_info.standard = product_standard.`code` LEFT JOIN product_state ON product_state.`code` = order_list.order_state LEFT JOIN product_apperance ON product_apperance.`code` = order_list.apperance LEFT JOIN product_brand ON product_brand.`code` = product_info.brand <where><if test='order.orderNum != null ' > order_num like '%'#{order.orderNum,jdbcType=VARCHAR}'%'</if><if test='order.operator != null ' > and operator like '%'#{order.operator,jdbcType=VARCHAR}'%'</if><if test='order.purchaseTime != null' > and purchase_time = #{order.purchaseTime,jdbcType=DATE}</if><if test='order.orderState != null' > and order_state = #{order.orderState,jdbcType=VARCHAR}</if><if test='order.serialNum != null' > and serial_num like '%'#{order.serialNum,jdbcType=VARCHAR}'%'</if><if test='states != null and states.length >0'> <foreach collection='states' item='state' separator=',' open=' and order_state in (' close=')'>#{state,jdbcType=BIGINT} </foreach></if> </where> </select>

這里的重點是:

<if test='states != null and states.length >0'> <foreach collection='states' item='state' separator=',' open=' and order_state in (' close=')'>#{state,jdbcType=BIGINT} </foreach></if>

把多個state的or關系轉化為 states in (state1,state2,state3...)

in中用foreach循環(huán)

mybatis plus and 和or合并寫法記錄一下and 和 or 混合使用

sql 語句實現

SELECT * FROM somc_operation_plan WHERE ( title LIKE ’%測試%’ AND ( charge_user = ’xxx’ OR execute_user = ’xxx’ ) )

LambdaQueryWrapper<SomcOperationPlan> queryWrapper = new LambdaQueryWrapper<>();queryWrapper.like(StringUtils.isNotEmpty(operationPlan.getTitle()), SomcOperationPlan::getTitle, operationPlan.getTitle()).and(wrapper -> wrapper.eq(StringUtils.isNotEmpty(operationPlan.getChargeUser()), SomcOperationPlan::getChargeUser, operationPlan.getChargeUser()).or().eq(StringUtils.isNotEmpty(operationPlan.getExecuteUser()), SomcOperationPlan::getExecuteUser, operationPlan.getExecuteUser()));

以上為個人經驗,希望能給大家一個參考,也希望大家多多支持好吧啦網。

標簽: Mybatis 數據庫
相關文章:
主站蜘蛛池模板: 国产视频中文字幕 | 黄色美女免费网站 | 美女视频免费黄的 | 国产日韩欧美综合在线 | 国产精品久久久久一区二区 | 国产一级黄色网 | www黄网| 午夜国产视频 | 欧美一级二级毛片视频 | 亚洲精品国产一区二区三 | 成人三级在线视频 | 一本久道久久综合婷婷五 | 国产成人午夜性a一级毛片 国产成人午夜性视频影院 国产成人香蕉久久久久 | 亚洲国产精品线播放 | 亚洲精品久久久久中文字幕一区 | 日韩精品视频一区二区三区 | 114毛片免费观看网站 | 久久免费精品一区二区 | 爆操巨乳美女 | 国产日本欧美亚洲精品视 | 免费特黄一区二区三区视频一 | 日本欧美一区二区三区在线 | 九九热久久免费视频 | 国产成人精品实拍在线 | 二区三区在线 | 韩国毛片一级 | 扒开双腿猛进入爽爽在线观看 | 欧美成人午夜在线全部免费 | 日本道综合一本久久久88 | 日本在线亚州精品视频在线 | 人摸人操 | 三级理论手机在线观看视频 | 天天看片天天爽_免费播放 天天看夜夜 | 中文字幕人成不卡一区 | 亚洲国产精品网站久久 | 空姐毛片| 成人羞羞视频国产 | 韩国一级毛片 | 亚洲一区日韩一区欧美一区a | 欧美与黑人午夜性猛交久久久 | 国产亚洲欧洲一区二区三区 |