Hi,
You can do this using one of these two tricks.
1) You can pass the configuration parameter to the query by adding it as a parameter to the Mapper.
2) You can add an Interceptor that will add the value to the map that is passed to the query.
Christian
De : mybati...@googlegroups.com [mailto:mybati...@googlegroups.com] De la part de Flavio
Envoyé : July-25-12 3:25 AM
À : mybati...@googlegroups.com
Objet : Condition on configuration parameter
I'm trying to have a conditional query fragment, based upon a parameter which comes from the mybatis configuration, rather than a query parameter. Something like this:
<sql id="frag">
<if test="col_name != null">
SELECT * FROM TABLE WHERE ${col.name}=#{value}
</if>
<if test="col_name == null">
SELECT * FROM TABLE WHERE SAMPLECOL=#{value}
</if>
</sql>
where the value of col_name is a global parameter, specified inside the .properties file read by the mybatis configuration.
Apparently this does not work; looking at the source code, it seems that the OGNL expression evaluator is not aware of the configuration properties (which instead are working when I have the parameter substitution, through ${...} inside the SQL). Is it possible to do this?
Hi,
You can do this using one of these two tricks.
1) You can pass the configuration parameter to the query by adding it as a parameter to the Mapper.
2) You can add an Interceptor that will add the value to the map that is passed to the query.
Christian
De : mybati...@googlegroups.com [mailto:mybatis-user@googlegroups.com] De la part de Flavio
Envoyé : July-25-12 3:25 AM
À : mybati...@googlegroups.com
Objet : Condition on configuration parameter