亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

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

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

瀏覽:15日期:2023-10-18 16:45:28
Mybatis and和循環or混用

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

最終轉換成用 IN實現:

場景

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

本來想用and 和 or 但是 or的條件是個數組參數, 需要遍歷states , 可能0個可能多個, 拼了半天沒有成功 , 最后發現用 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循環

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 數據庫
相關文章:
主站蜘蛛池模板: 国产精品一区二区久久不卡 | 成人美女黄网站视频大全 | 热门国产xvideos中文 | 99久久精品国产一区二区成人 | 啪视频在线观看 | 看a级毛片 | 玖玖国产在线 | 成人午夜小视频手机在线看 | 日本mv精品中文字幕 | 国产精品v| 久久6免费视频 | 最近手机中文在线视频 | 国产成人精品微拍视频 | 国产青青操 | 国产精品入口麻豆免费 | 国产精品亚洲精品日韩已满 | 免费无尽xxx视频 | 日本黄色录像 | 国产精品一库二库三库 | 制服丝袜中文在线 | 国产黄色片大全 | 久久99国产这里有精品视 | 成人亚洲国产 | 亚洲福利国产精品17p | 2048国产精品原创综合在线 | 日韩在线一区二区三区视频 | 亚洲欧美高清在线 | 久久国产精品亚洲 | 国产小视频精品 | 性做久久久久久久久男女 | 国产精品视频免费一区二区三区 | 亚洲精品国产成人99久久 | 国产高清在线视频 | 成人爽爽激情在线观看 | 亚洲欧洲日产国码在线观看 | 国产青青在线 | 性欧美高清理论片 | 欧美日韩一区二区三区在线视频 | 国产成人精品免费视频动漫 | yjizz视频国产网站在线播放 | 韩国在线看免费观看高清 |