1

I have a common sql tag that should change dynamically depending on where it was included.

 <sql id="common">
        from customer_order as co inner join status as st on st.id = co.status_id
        left join status as sst on sst.id = co.sub_status_id
        inner join customer as c on c.id = co.customer_id
        inner join user as u on u.id = co.created_by
        left join customer_account as acc on acc.id = c.account_type_id
        left join customer_type as typ on typ.id = c.party_type
        left join sale_channel as ch on ch.id = co.saleschannel_id
       <choose>
        <when test="${ordernotes} eq 'true'">
            inner join order_note as ordn on ordn.order_id = co.id 
        </when>
        <when test="${vendorordernotes} eq 'true'">
           ... join with other tables
        </when>
        </choose>
</sql>

This is how I am including the sql above.

  <select id="x" resultType="long">
        select count(distinct ordn.id) 
        <include refid="common">
            <property name="ordernotes" value="true"/>
        </include>
    </select>

And

<select id="y" resultType="long">
        select count(distinct von.id)
        <include refid="common">
            <property name="vendorordernotes" value="true"/>
        </include>
 </select>

I cannot get the '' code to work. How do I go about it.

Exception:

Was expecting one of:
    ":" ...
    "not" ...
    "+" ...
    "-" ...
    "~" ...
    "!" ...
    "(" ...
    "true" ...
    "false" ...
    "null" ...
    "#this" ...
    "#root" ...
    "#" ...
    "[" ...
    "{" ...
    "@" ...
    "new" ...
    <IDENT> ...
    <DYNAMIC_SUBSCRIPT> ...
    "\'" ...
    "`" ...
    "\"" ...
    <INT_LITERAL> ...
    <FLT_LITERAL> ...
    ] 
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression '${ordernotes} eq 'true''. Cause: org.apache.ibatis.ognl.ExpressionSyntaxException: Malformed OGNL expression: ${ordernotes} eq 'true' [org.apache.ibatis.ognl.ParseException: Encountered " "$" "$ "" at line 1, column 1.
Was expecting one of:

1 Answer 1

1

Parameter it is not interpreted well. Surround parameter with quotes: <when test="'${ordernotes}' eq 'true'">, and it becomes a simple string compare.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.