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

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

在mybatis中使用mapper進行if條件判斷

瀏覽:121日期:2023-10-20 13:54:46
目的:

在使用mybatis框架中mapper文件有自動生成,但有時需要自己添加sql語句進行開發,當遇到需要使用 if進行條件判斷的時候該怎么寫?

查詢sql語句如下:

<select parameterType='com.pojo.QueryDetailReq' resultType='com.pojo.MxDataInfo'> select * from db_trd.tb_trd_secu_order where order_status=6 <if test='channelNo!= null' > and channel_no = #{channelNo,jdbcType=INTEGER} </if> <if test='reportNo!=null' > and report_no = #{reportNo,jdbcType=INTEGER} </if> <if test='companyNo!= null' > and company_no = #{companyNo,jdbcType=VARCHAR} </if> <if test='orderNo!=null' > and order_no = #{orderNo,jdbcType=INTEGER} </if> <if test='stockCode!=null' > and stock_code = #{stockCode,jdbcType=VARCHAR} </if> </select>語句解析:

1、if語句的格式 ;

2、test中的字段 為parameterType中 com.pojo.QueryDetailReq 的對象 (入參)

3、resultType 為返回查詢數據對象 (結果集)

補充:mabatis mapper文件中 使用if條件插入字段和數據

有時候我們插入數據庫數據的時候,插入字段都是不確定的,那么我們也可以用if條件來過濾一些字段

廢話不多說,直接上代碼

<insert parameterType='hashmap'> insert into t_order <trim prefix='(' suffix=')' suffixOverrides=','> <if test='orderNo != null'> orderNo, </if> <if test='serviceName != null'> serviceName, </if> <if test='idcard != null'> idcard, </if> <if test='name != null'> name, </if> <if test='requestData != null'> requestData, </if> <if test='responseData != null'> responseData, </if> <if test='status != null'> status, </if> <if test='updatedTime != null'> updatedTime, </if> <if test='completionTime != null'> completionTime, </if> <if test='bae007 != null'> bae007, </if> <if test='operId != null'> operId, </if> <if test='operName != null'> operName, </if> <if test='remark != null'> remark, </if> </trim> <trim prefix='values (' suffix=')' suffixOverrides=','> <if test='orderNo != null'> #{orderNo}, </if> <if test='serviceName != null'> #{serviceName}, </if> <if test='idcard != null'> #{idcard}, </if> <if test='name != null'> #{name}, </if> <if test='requestData != null'> #{requestData}, </if> <if test='responseData != null'> #{responseData}, </if> <if test='status != null'> #{status}, </if> <if test='updatedTime != null'> #{updatedTime}, </if> <if test='completionTime != null'> #{completionTime}, </if> <if test='bae007 != null'> #{bae007}, </if> <if test='operId != null'> #{operId}, </if> <if test='operName != null'> #{operName}, </if> <if test='remark != null'> #{remark}, </if> </trim> </insert>

經過測試,是可以實現的。

以上為個人經驗,希望能給大家一個參考,也希望大家多多支持好吧啦網。如有錯誤或未考慮完全的地方,望不吝賜教。

標簽: Mybatis 數據庫
相關文章:
主站蜘蛛池模板: 亚洲综合欧美在线 | 第一区| 亚洲欧美日韩综合在线播放 | 婷婷丁香五月中文字幕 | 欧美福利片在线观看 | 亚洲第三十七页 | 免费一级欧美片在线观免看 | 欧洲一级鲁丝片免费 | 亚洲成a人片在线网站 | 亚洲国产高清在线 | 中国一级黄色大片 | 国产精品免费大片一区二区 | 亚洲国产精品婷婷久久 | 欧美一级特黄高清免费 | 站长工具亚洲 | 亚洲国内 | 成 人 免费观看网站 | 一级女性全黄久久生活片 | 日本特交大片免费观看 | 国产人成精品香港三级古代 | 日本欧美中文字幕人在线 | 免费高清毛片 | 在线观看www视频 | 国产高清国内精品福利色噜噜 | 中文字幕日韩国产 | 亚洲精品美女一区二区三区乱码 | 亚洲视频网站在线观看 | 在线观看黄网视频免费播放 | 720lu牛牛刺激自拍视频 | 久久精品国产99久久无毒不卡 | 中文字字幕 | 久久国产视频在线观看 | 亚洲国产色图 | 2020久久精品国产免费 | 国产一区二区三区精品视频 | 国产精品久久久久aaaa | 日韩a级一片在线观看 | 1717she精品国产真正免费 | 国产在线高清一级毛片 | 亚洲国产综合精品中文第一区 | 九九九色视频在线观看免费 |