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

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

在mybatis中使用mapper進(jìn)行if條件判斷

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

在使用mybatis框架中mapper文件有自動(dòng)生成,但有時(shí)需要自己添加sql語句進(jìn)行開發(fā),當(dāng)遇到需要使用 if進(jìn)行條件判斷的時(shí)候該怎么寫?

查詢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 的對象 (入?yún)ⅲ?/p>

3、resultType 為返回查詢數(shù)據(jù)對象 (結(jié)果集)

補(bǔ)充:mabatis mapper文件中 使用if條件插入字段和數(shù)據(jù)

有時(shí)候我們插入數(shù)據(jù)庫數(shù)據(jù)的時(shí)候,插入字段都是不確定的,那么我們也可以用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>

經(jīng)過測試,是可以實(shí)現(xiàn)的。

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教。

標(biāo)簽: Mybatis 數(shù)據(jù)庫
相關(guān)文章:
主站蜘蛛池模板: 午夜a级理论片915影院 | 中文久久| 精品一区二区久久 | 国内精品99 | 老司机精品福利视频 | 日韩国产高清在线观看 | 在线国产一区 | 日本欧美国产在线观看 | 日韩二区 | 国产精品美女在线观看 | 中文字幕第三页 | 久久久国产一区 | 国产高清视频在线观看播放 | 精精国产xxxx视频在线播放 | av在线播放网址 | 一级毛片大全免费播放 | 日韩精品在线观看网站 | 伊人免费在线观看高清 | 欧美一级免费看 | 亚洲一区二区中文字幕 | 久久毛片 | 亚洲欧美日本在线 | 中文字幕一区二区三区四区五区 | 成人久久久久久久久 | 国产成人99久久亚洲综合精品 | 久久一级免费视频 | 视频一区二区三区中文字幕 | 日韩国产三区 | 欧美日韩综合一区 | 国产精品mv在线观看 | 高清国产一区二区 | 中文字幕成人在线 | 欧美成人猛片aaaaaaa | 欧美男人天堂 | 久久精品国产99国产精品 | 色接久久| 欧美日韩视频在线第一区 | 欧美黑人激情 | 欧美精品一区在线发布 | 亚洲国产成人精品一区二区 | 中文字幕亚洲欧美 |