国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術(shù)文章
文章詳情頁

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

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

這次項(xiàng)目用到一個(gè)and和or混用的場(chǎng)景 , 因?yàn)橛玫蕉鄠€(gè)or(循環(huán)), 沒想到好的辦法

最終轉(zhuǎn)換成用 IN實(shí)現(xiàn):

場(chǎng)景

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

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

DAO層接口

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

<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>

這里的重點(diǎn)是:

<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>

把多個(gè)state的or關(guān)系轉(zhuǎn)化為 states in (state1,state2,state3...)

in中用foreach循環(huán)

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

sql 語句實(shí)現(xiàn)

SELECT * FROM somc_operation_plan WHERE ( title LIKE ’%測(cè)試%’ 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()));

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Mybatis 數(shù)據(jù)庫
相關(guān)文章:
主站蜘蛛池模板: 久草在线视频免费资源观看 | 网红毛片| 欧美成人在线免费观看 | 欧美一级视频高清片 | 免费乱人伦 | 欧美一级一片 | 欧美成成人免费 | 欧美一级片免费在线观看 | 亚洲日本在线观看 | 男女视频免费 | 大臿蕉香蕉大视频成人 | 欧美久在线观看在线观看 | 亚洲成a人片在线观看中文 亚洲成a人片在线观看中文!!! | 初爱视频教程在线观看高清 | 国产精品久久久久久麻豆一区 | 日本成人在线视频网站 | 国产精品成人免费视频不卡 | 日本免费大黄在线观看 | 另类自拍 | 欧美性xxxx极品高清 | 在线步兵区| 久久九九国产 | 欧美成人免费观看 | 免费国产成人α片 | 欧美日韩一级片在线观看 | 国产成人精选免费视频 | 99久久精品全部 | 国产a网| 午夜三级毛片 | 国产精自产拍久久久久久蜜 | 久久久精品久久视频只有精品 | 一区二区中文字幕亚洲精品 | 97久久精品视频 | 亚洲精品推荐 | 免费视频男女 | 久久久国产高清 | 亚洲一区二区三区四区在线 | 日本毛片免费看 | 黄色一级片在线看 | 综合在线播放 | 久草在线播放视频 |