国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

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

mybatis if標(biāo)簽判斷不生效的解決方法

瀏覽:43日期:2023-10-20 07:28:21

實際需求

<if test='computationRule == ’1’'> FROM app_sz_bbb a</if><if test='computationRule == ’2’'> FROM app_ccc a</if>

這種情況不生效,

原因:mybatis是用OGNL表達(dá)式來解析的,在OGNL的表達(dá)式中,’0’會被解析成字符,java是強類型的,char 和 一個string 會導(dǎo)致不等,所以if標(biāo)簽中的sql不會被解析。

先說怎么解決

三種:

加 .toString()

<if test='computationRule == ’1’.toString()'> FROM app_sz_bbb a</if><if test='computationRule == ’2’.toString()'> FROM app_ccc a</if>

choose when 標(biāo)簽代替

<choose> <when test='computationRule == ’1’'> FROM app_sz_bbb a </when> <otherwise> FROM app_sz_bbb a </otherwise> </choose>

單引號 換成雙引號

<if test=’computationRule == '1'’> FROM app_sz_bbb a</if><if test=’computationRule == '2'’> FROM app_ccc a</if>MyBatis 中if 標(biāo)簽 判斷字符串不生效

異常sql 的mapper 文件:

<if test='isBound != null and isBound !=’’ and isBound == ’1’'> and box_sid is not null </if><if test='isBound != null and isBound !=’’ and isBound == ’2’'> and box_sid is null </if>

正確sql 的mapper 文件

<if test='isBound != null and isBound !=’’ and isBound == ’1’.toString()'> and box_sid is not null </if><if test='isBound != null and isBound !=’’ and isBound == ’2’.toString()'> and box_sid is null </if>

到此這篇關(guān)于mybatis if標(biāo)簽判斷不生效的解決方法的文章就介紹到這了,更多相關(guān)mybatis if標(biāo)簽判斷不生效內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Mybatis 數(shù)據(jù)庫
相關(guān)文章:
主站蜘蛛池模板: 遂平县| 永丰县| 宁波市| 若尔盖县| 商南县| 旬邑县| 金湖县| 固始县| 洱源县| 奇台县| 如皋市| 偏关县| 靖边县| 社会| 阿坝| 郁南县| 靖西县| 内乡县| 牙克石市| 青浦区| 平泉县| 利川市| 宁津县| 武强县| 新田县| 襄垣县| 广州市| 康马县| 营口市| 龙南县| 甘孜县| 昌吉市| 姚安县| 长寿区| 鄂温| 宁南县| 扶余县| 山丹县| 富民县| 微山县| 盘锦市|