Mybatis XML出现OGNL的问题

2019-03-09  本文已影响0人  TTTTTriM
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出现OGNL的问题,原因是mybatis xml写法不满足OGNL要求,修改即可解决。
部分语法对照表:

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

当然还有一种解决办法,在合适的地方加入<![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>
上一篇下一篇

猜你喜欢

热点阅读