您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關怎么在Mybatis中利用 if語句判斷條件是否等于一個數(shù)字,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關知識有一定的了解。
在Mybatis中 mapper中
boolean updateRegisterCompanyFlag(@Param(value = "companyId") String companyId,
@Param(value = "flag") String flag);
傳入的flag類型為String,但在mapper.XML中進行判斷是下意識地以為判斷的值要加上引號
<if test=" '4' == flag "> , LAST_CHECK_TIME = sysdate </if>
但是這樣寫,傳入flag=“4”后,這個if語句一直不成立s
ql沒有拼接。后來網(wǎng)上查了一番后將 test 中的 4 的引號去除才成功。
<if test=" 4 == flag "> , LAST_CHECK_TIME = sysdate </if>
記錄一下,以防忘記。。。
補充知識:Mybatis中xml的有關if test以及==的用法
Mybatis中,通常都要在mapper.xml中寫復雜的sql語句,結(jié)合頁面的查詢篩選條件,需要在sql語句中加入
<if test=""></if>等的判斷。而這test 后面的字段也是來自jsp或者html頁面,但是不是隨便書寫的。
與頁面都要一一對應,除此之外,還需要在實體類中有定義。
另外,mybatis中 <if test=>等于的條件怎么寫?
注意 僅僅需要將雙引號和單引號的位置換一下即可!!!
<sql id="queryData"> select '集團' src_dbct_cd, substr(stats_mo,1,4) year, substr(stats_mo,5,6) month, sum(all_zb_cars) all_zb_cars,sum(all_kb_cars) all_kb_cars,sum(all_wd_cars) all_wd_cars, sum(all_zb_cars+all_kb_cars+all_wd_cars) all_cars_total, sum(round(all_zb_exp/10000,2)) all_zb_exp,sum(round(all_kb_exp/10000,2)) all_kb_exp,sum(round(all_wd_exp/10000,2)) all_wd_exp, sum(round(all_zb_exp/10000+all_kb_exp/10000+all_wd_exp/10000,2)) all_exp_total, sum(zb_cars) zb_cars,sum(kb_cars) kb_cars, sum(zb_cars+kb_cars) cars_total, sum(round(zb_net_wgt/10000000,2)) zb_net_wgt,sum(round(kb_net_wgt/10000000,2)) kb_net_wgt, sum(round(ifnull(zb_net_wgt/10000000,0)+ifnull(kb_net_wgt/10000000,0),2)) wgt_total, sum(round(zb_exp/10000,2)) zb_exp,sum(round(kb_exp/10000,2)) kb_exp, sum(round(zb_exp/10000+kb_exp/10000,2)) exp_total, sum(zb_lod_mnt) zb_lod_mnt,sum(kb_lod_mnt) kb_lod_mnt, sum(ifnull(zb_lod_mnt,0)+ifnull(kb_lod_mnt,0)) lod_mnt_total, sum(zb_wait_mnt) zb_wait_mnt,sum(kb_wait_mnt) kb_wait_mnt, sum(ifnull(zb_wait_mnt,0)+ifnull(kb_wait_mnt,0)) wait_mnt_total, concat(round(sum(zb_dlyd_cars/zb_cars)*100,2),'%') zb_dlyd_pt, concat(round(sum(kb_dlyd_cars/kb_cars)*100,2),'%') kb_dlyd_pt, concat(round(sum(ifnull(zb_dlyd_cars/zb_cars,0)+ifnull(kb_dlyd_cars/kb_cars,0))*100,2),'%') dlyd_pt_total, concat(round(sum(zb_frqc_dlyd_cars/zb_cars)*100,2),'%') zb_frqc_dlyd, concat(round(sum(kb_frqc_dlyd_cars/kb_cars)*100,2),'%') kb_frqc_dlyd, concat(round(sum(ifnull(zb_frqc_dlyd_cars/zb_cars,0)+ifnull(kb_frqc_dlyd_cars/kb_cars,0))*100,2),'%') frqc_dlyd_total, sum(zb_dlyd_mnt) zb_dlyd_mnt,sum(kb_dlyd_mnt) kb_dlyd_mnt, sum(ifnull(zb_dlyd_mnt,0)+ifnull(kb_dlyd_mnt,0)) dlyd_mnt_total, round(ifnull(sum(zb_sys_mlg)/sum(zb_stip_mnt),0),2) zb_stip_speed, round(ifnull(sum(kb_sys_mlg)/sum(kb_stip_mnt),0),2) kb_stip_speed, (round(ifnull(sum(zb_sys_mlg)/sum(zb_stip_mnt),0)+ifnull(sum(kb_sys_mlg)/sum(kb_stip_mnt),0),2)) stip_speed_total, round(ifnull(sum(zb_est_mlg)/sum(zb_actl_mnt),0),2) zb_actl_speed, round(ifnull(sum(kb_est_mlg)/sum(kb_actl_mnt),0),2) kb_actl_speed, (round(ifnull(sum(zb_est_mlg)/sum(zb_actl_mnt),0)+ifnull(sum(kb_est_mlg)/sum(kb_actl_mnt),0),2)) actl_speed_total, sum(round(zb_pnlt/10000,2)) zb_pnlt,sum(round(kb_pnlt/10000,2)) kb_pnlt, sum(ifnull(round(zb_pnlt/10000,2),0)+ifnull(round(kb_pnlt/10000,2),0)) pnlt_total, sum(zb_uld_wait_mnt) zb_uld_wait_mnt,sum(kb_uld_wait_mnt) kb_uld_wait_mnt,sum(wd_uld_wait_mnt) wd_uld_wait_mnt, round((ifnull(sum(zb_uld_wait_mnt),0)+ifnull(sum(kb_uld_wait_mnt),0)+ifnull(sum(wd_uld_wait_mnt),0))/ (ifnull(sum(all_zb_cars),0)+ifnull(sum(all_kb_cars),0)+ifnull(sum(all_wd_cars),0)),2) uld_wait_mnt_total, sum(zb_uld_mnt) zb_uld_mnt,sum(kb_uld_mnt) kb_uld_mnt,sum(wd_uld_mnt) wd_uld_mnt, sum(ifnull(zb_uld_mnt,0)+ifnull(kb_uld_mnt,0)+ifnull(wd_uld_mnt,0)) uld_mnt_total, concat(round(sum(zb_brk_cars/zb_mlg/10000)*100,2),'%') zb_brk_cars, concat(round(sum(kb_brk_cars/kb_mlg/10000)*100,2),'%') kb_brk_cars, concat(round(sum(wd_brk_cars/wd_mlg/10000)*100,2),'%') wd_brk_cars, concat((round(sum(ifnull(zb_brk_cars/zb_mlg/10000,0)+ifnull(kb_brk_cars/kb_mlg/10000,0)+ifnull(wd_brk_cars/wd_mlg/10000,0))*100,2)),'%') brk_cars_total, concat(round(sum(zb_accdt_cars/zb_mlg/10000)*100,2),'%') zb_accdt_cars, concat(round(sum(kb_accdt_cars/kb_mlg/10000)*100,2),'%') kb_accdt_cars, concat(round(sum(wd_accdt_cars/wd_mlg/10000)*100,2),'%') wd_accdt_cars, concat((round(sum(ifnull(zb_accdt_cars/zb_mlg/10000,0)+ifnull(kb_accdt_cars/kb_mlg/10000,0)+ifnull(wd_accdt_cars/wd_mlg/10000,0))*100,2)),'%') accdt_cars_total, concat(round(sum(actl_tms/stip_tms)*100,2),'%') tms_total from bdrpt.kd_car_trans_mont_stats where 1=1 <if test="stats_mo != null and stats_mo != ''" > and concat(SUBSTR(stats_mo,1,4),'-',SUBSTR(stats_mo,5,6))=#{stats_mo} </if> <if test='SRC_DBCT_CD == "2"'> and src_dbct_cd = '分撥' </if> GROUP BY substr(stats_mo,5,6) UNION select l.location_name src_dbct_cd, substr(stats_mo,1,4) year, substr(stats_mo,5,6) month, all_zb_cars,all_kb_cars,all_wd_cars, (all_zb_cars+all_kb_cars+all_wd_cars) all_cars_total, round(all_zb_exp/10000,2) all_zb_exp,round(all_kb_exp/10000,2) all_kb_exp,round(all_wd_exp/10000,2) all_wd_exp, round(all_zb_exp/10000+all_kb_exp/10000+all_wd_exp/10000,2) all_exp_total, zb_cars,kb_cars, (zb_cars+kb_cars) cars_total, round(zb_net_wgt/10000000,2) zb_net_wgt,round(kb_net_wgt/10000000,2) kb_net_wgt, round(ifnull(zb_net_wgt/10000000,0)+ifnull(kb_net_wgt/10000000,0),2) wgt_total, round(zb_exp/10000,2) zb_exp,round(kb_exp/10000,2) kb_exp, round(zb_exp/10000+kb_exp/10000,2) exp_total, zb_lod_mnt,kb_lod_mnt, (ifnull(zb_lod_mnt,0)+ifnull(kb_lod_mnt,0)) lod_mnt_total, zb_wait_mnt,kb_wait_mnt, (ifnull(zb_wait_mnt,0)+ifnull(kb_wait_mnt,0)) wait_mnt_total, concat(round(zb_dlyd_cars/zb_cars*100,2),'%') zb_dlyd_pt, concat(round(kb_dlyd_cars/kb_cars*100,2),'%') kb_dlyd_pt, concat(round((ifnull(zb_dlyd_cars/zb_cars,0)+ifnull(kb_dlyd_cars/kb_cars,0))*100,2),'%') dlyd_pt_total, concat(round(zb_frqc_dlyd_cars/zb_cars*100,2),'%') zb_frqc_dlyd, concat(round(kb_frqc_dlyd_cars/kb_cars*100,2),'%') kb_frqc_dlyd, concat(round((ifnull(zb_frqc_dlyd_cars/zb_cars,0)+ifnull(kb_frqc_dlyd_cars/kb_cars,0))*100,2),'%') frqc_dlyd_total, zb_dlyd_mnt,kb_dlyd_mnt, (ifnull(zb_dlyd_mnt,0)+ifnull(kb_dlyd_mnt,0)) dlyd_mnt_total, round(ifnull(sum(zb_sys_mlg)/sum(zb_stip_mnt),0),2) zb_stip_speed, round(ifnull(sum(kb_sys_mlg)/sum(kb_stip_mnt),0),2) kb_stip_speed, (round(ifnull(sum(zb_sys_mlg)/sum(zb_stip_mnt),0)+ifnull(sum(kb_sys_mlg)/sum(kb_stip_mnt),0),2)) stip_speed_total, round(ifnull(sum(zb_est_mlg)/sum(zb_actl_mnt),0),2) zb_actl_speed, round(ifnull(sum(kb_est_mlg)/sum(kb_actl_mnt),0),2) kb_actl_speed, (round(ifnull(sum(zb_est_mlg)/sum(zb_actl_mnt),0)+ifnull(sum(kb_est_mlg)/sum(kb_actl_mnt),0),2)) actl_speed_total, round(zb_pnlt/10000,2) zb_pnlt,round(kb_pnlt/10000,2) kb_pnlt, (ifnull(round(zb_pnlt/10000,2),0)+ifnull(round(kb_pnlt/10000,2),0)) pnlt_total, zb_uld_wait_mnt,kb_uld_wait_mnt,wd_uld_wait_mnt, round((ifnull(sum(zb_uld_wait_mnt),0)+ifnull(sum(kb_uld_wait_mnt),0)+ifnull(sum(wd_uld_wait_mnt),0))/ (ifnull(sum(all_zb_cars),0)+ifnull(sum(all_kb_cars),0)+ifnull(sum(all_wd_cars),0)),2) uld_wait_mnt_total, zb_uld_mnt,kb_uld_mnt,wd_uld_mnt, (ifnull(zb_uld_mnt,0)+ifnull(kb_uld_mnt,0)+ifnull(wd_uld_mnt,0)) uld_mnt_total, concat(round(zb_brk_cars/zb_mlg/10000*100,2),'%') zb_brk_cars, concat(round(kb_brk_cars/kb_mlg/10000*100,2),'%') kb_brk_cars, concat(round(wd_brk_cars/wd_mlg/10000*100,2),'%') wd_brk_cars, concat((round((ifnull(zb_brk_cars/zb_mlg/10000,0)+ifnull(kb_brk_cars/kb_mlg/10000,0)+ifnull(wd_brk_cars/wd_mlg/10000,0))*100,2)),'%') brk_cars_total, concat(round(zb_accdt_cars/zb_mlg/10000*100,2),'%') zb_accdt_cars, concat(round(kb_accdt_cars/kb_mlg/10000*100,2),'%') kb_accdt_cars, concat(round(wd_accdt_cars/wd_mlg/10000*100,2),'%') wd_accdt_cars, concat((round((ifnull(zb_accdt_cars/zb_mlg/10000,0)+ifnull(kb_accdt_cars/kb_mlg/10000,0)+ifnull(wd_accdt_cars/wd_mlg/10000,0))*100,2)),'%') accdt_cars_total, concat(round(actl_tms/stip_tms*100,2),'%') tms_total from bdrpt.kd_car_trans_mont_stats t LEFT JOIN bdkdbase.location l on t.src_dbct_cd = l.location_xid where 1=1 <if test="stats_mo != null and stats_mo != ''" > and concat(SUBSTR(stats_mo,1,4),'-',SUBSTR(stats_mo,5,6))=#{stats_mo} </if> <if test='SRC_DBCT_CD == "1"'> and src_dbct_cd = '集團' </if> <if test="SRC_DBCT_NM != null and SRC_DBCT_NM != ''"> and src_dbct_cd = #{SRC_DBCT_NM} </if> GROUP BY src_dbct_cd,substr(stats_mo,5,6) </sql> <!-- 查詢數(shù)據(jù) --> <select id="pageQuery" resultType="map"> <include refid="queryData"></include> </select>
關于怎么在Mybatis中利用 if語句判斷條件是否等于一個數(shù)字就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。