av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

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

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

瀏覽:149日期: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级黄毛片 | 亚洲一区网站 | 日韩精品一区二区三区四区 | 成人永久免费视频 | 国产在线视频一区二区 | 深夜福利影院 | 在线一区二区三区 | 日本免费毛片 | 九九热免费视频 | 国产欧美在线观看 | 免费在线观看黄色片 | 欧美在线a| 日韩午夜在线观看 | 性欧美8khd高清极品 | 亚洲成人免费av | 成人一区二区三区 | 婷婷视频网 | 中文字幕99| 免费在线观看毛片 | 中文字幕在线观看亚洲 | 亚洲国产成人精品女人久久久 | 欧美激情久久久 | 一级片在线免费观看 | 看片黄全部免费 | 欧美一级淫片bbb一84 | 一本到av | 日韩小视频 | 激情视频小说 | 亚洲视频在线播放 | 欧美顶级黄色大片免费 | 伊人999 | 欧美精品乱码99久久蜜桃 | 日本少妇高潮达到高潮 | 国产精品免费一区二区三区 | 伊人精品视频 | 中文字幕欧美激情 | 欧美午夜精品久久久久免费视 | 亚洲欧美日韩国产精品 | 日日操日日射 | 国产在线视频一区二区 | 神马九九 |