Gangnus
Gangnus

Reputation: 24484

What parameters are parsed the first in myBatis mapper, # or $ ones?

I use a tag in the mapper, and text in it contains some external #{} parameters:

<sql id="searchInInterval">
    (r01.start between to_date(#{${what}Date}, 'MMYYYY') and to_date(#{thirdDate}, 'MMYYYY'))

Later in the XML mapper, when I use it

<include refid="searchInInterval">
    <property name="what" value="first"/>
</include>

, what parameter will be parsed the first? # or $ one?

Upvotes: 0

Views: 279

Answers (1)

ave
ave

Reputation: 3614

${} (text substitution) is resolved first.

In case ${} is inside a <sql /> like your example, MyBatis tries to replace it when parsing the mapper file (i.e. during application startup).
If there is no matching properties found [1] in this phase, MyBatis tries to replace it by looking up the runtime parameters when the statement is executed.

[1] In addition to the <property /> nested inside <include />, you can declare properties in the configuration as well.

Upvotes: 1

Related Questions