0
共通SQLタグが含まれている場所によって動的に変更する必要があります。MyBatisダイナミックSQLインクルードプロパティを使用する
<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>
これは、上記のSQLを含む方法です。
<select id="x" resultType="long">
select count(distinct ordn.id)
<include refid="common">
<property name="ordernotes" value="true"/>
</include>
</select>
そして
<select id="y" resultType="long">
select count(distinct von.id)
<include refid="common">
<property name="vendorordernotes" value="true"/>
</include>
</select>
私は '' コードを動作させることはできません。どのように私はそれについて行くのですか?
例外:それはうまく解釈されません
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: