프로그래밍/ErrorLog

org.apache.ibatis.ognl.ExpressionSyntaxException: Malformed OGNL expression

미냐님 2020. 7. 16. 15:28
728x90

MyBatis Dynamic(동적) SQL 에러

org.apache.ibatis.ognl.ExpressionSyntaxException: Malformed OGNL expression

 


스프링으로 코딩중 XML 매퍼에서 MyBatis Dynamic(동적) SQL 작성시 잘못된 구문이나, 오류가 있을 때 발생하였습니다.

<choose>
    <when test="status == 2 OR status == 4">
        ...
    </when>
    <otherwise>
        ...
    </otherwise>
</choose>

위와 같은 코드가 있다면, 실행시 아래와 같은 에러가 납니다.

org.springframework.web.util.NestedServletException: Request processing failed; 
nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: 
Error evaluating expression 'status == 2 OR status == 4'. Cause: 
org.apache.ibatis.ognl.ExpressionSyntaxException: Malformed OGNL expression: 
status == 2 OR status == 4 [org.apache.ibatis.ognl.ParseException: Encountered " <IDENT> "OR "" at line 1, column 13.
Was expecting one of:
    <EOF> 
    "," ...
    "=" ...
    "?" ...
    "||" ...
    "or" ...
    "&&" ...
    "and" ...
    "|" ...
    "bor" ...
    "^" ...
    "xor" ...
    "&" ...
    "band" ...
    "==" ...
    "eq" ...
    "!=" ...
    "neq" ...
    "<" ...
    "lt" ...
    ">" ...
    "gt" ...
    "<=" ...
    "lte" ...
    ">=" ...
    "gte" ...
    "in" ...
    "not" ...
    "<<" ...
    "shl" ...
    ">>" ...
    "shr" ...
    ">>>" ...
    "ushr" ...
    "+" ...
    "-" ...
    "*" ...
    "/" ...
    "%" ...
    "instanceof" ...
    "." ...
    "(" ...
    "[" ...
    <DYNAMIC_SUBSCRIPT> ...
    ]

 

동적 SQL을 사용할 때, OR 표기가 잘못되었기 때문에 에러가 발생했습니다.

OR 을 or 로 바꿔주면 해결됩니다. 그외 구문은 아래를 참고해주세요.

 

    "||" / "or" ...     // 또는

    "&&" / "and" ...    // 그리고

    "|" / "bor" ...     // 논리합

    "^" / "xor" ...     // 비트간의 XOR

    "&" /  "band" ...   // 논리곱



    "==" / "eq" ...     // 같다

    "!=" / "neq" ...    // 같지않다

    "<" / "lt" ...      // 작다

    ">" / "gt" ...      // 크다

    "<=" / "lte" ...    // 작거나 같다

    ">=" / "gte" ...    // 크거나 같다



    "in" ...            // 포함

    "not" ...           // 부정

    "<<" / "shl" ...    // 왼쪽 시프트

    ">>" / "shr" ...    // 오른쪽 시프트

    ">>>" / "ushr" ...  // 부호 없는 오른쪽 시프트

    "+" ...             // 더하기

    "-" ...             // 빼기

    "*" ...             // 곱하기

    "/" ...             // 나누기 

    "%" ...             // 몫
728x90