Mybatis XML出現(xiàn)OGNL的問(wèn)題

org.apache.ibatis.ognl.ExpressionSyntaxException: Malformed OGNL expression: xxx is null || xxx == ''
[org.apache.ibatis.ognl.ParseException: Encountered " "xxx is null || xxx == ''" at line 1, column 1.
Was expecting one of:
 ":" ...
 "not" ...
 "+" ...
 "-" ...
 "~" ...
 "!" ...
 "(" ...
 "true" ...
 "false" ...
 "null" ...
 "#this" ...
 "#root" ...
 "#" ...
 "[" ...
 "{" ...
 "@" ...
 "new" ...
 <IDENT> ...
 <DYNAMIC_SUBSCRIPT> ...
 "\'" ...
 "`" ...
 "\"" ...
 <INT_LITERAL> ...
 <FLT_LITERAL> ...
 ]] with root cause
org.apache.ibatis.ognl.ParseException: Encountered ""xxx is null || xxx == ''" at line 1, column 1.
Was expecting one of:
 ":" ...
 "not" ...
 "+" ...
 "-" ...
 "~" ...
 "!" ...
 "(" ...
 "true" ...
 "false" ...
 "null" ...
 "#this" ...
 "#root" ...
 "#" ...
 "[" ...
 "{" ...
 "@" ...
 "new" ...
 <IDENT> ...
 <DYNAMIC_SUBSCRIPT> ...
 "\'" ...
 "`" ...
 "\"" ...
 <INT_LITERAL> ...
 <FLT_LITERAL> ...

mybatis出現(xiàn)OGNL的問(wèn)題,原因是mybatis xml寫(xiě)法不滿(mǎn)足OGNL要求,修改即可解決。
部分語(yǔ)法對(duì)照表:

bor(字符|)的英文         
xor      字符^的英文       
and      字符&&     
band    字符&       
eq     字符==      
neq    字符!=     
lt      字符<    
gt      字符>    
lte       字符<=   
 gte    字符>=    
shl    字符 <<    
shr    字符>>     
ushr    字符>>>

當(dāng)然還有一種解決辦法,在合適的地方加入<![CDATA[ xxxxx ]]> 也可以。
栗子:

  <select id="list" resultType="map">
        select
        id as chatMsgId,
        ask,
        answer,
        generate_time as generateTime
        from aibox_chat_message acm
        where
        acm.user_id = #{userId}
        and
        acm.serial_number = #{serialNumber}
        <choose>
            <when test="chatMessageId eq null bor chatMessageId eq ''">
                order by acm.generate_time desc
            </when>
            <otherwise>
                <if test="upOrDown eq 'UP'">
                    <![CDATA[ and acm.id < #{chatMessageId} ]]>
                    order by acm.generate_time desc
                </if>
                <if test="upOrDown eq 'DOWN'">
                    <![CDATA[ and acm.id > #{chatMessageId} ]]>
                    order by acm.generate_time asc
                </if>
            </otherwise>
        </choose>
        limit #{count}
    </select>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容