Is there a way in mybatis to test if a certain parameter is contained in the query parameter map?
I'm looking for something like this:
<select id="selectByKey" resultMap="MyObjectMap" parameterType="map">
select obj.* from obj where obj.id=#{id:VARCHAR}
<!-- I'm looking for a method like that below -->
<if test="parameterExists('forUpdate')">
<if test="forUpdate == 1">
for update
</if>
</if>
</select>
You can use this test:
<if test="_parameter.containsKey('forUpdate')">your code....</if>
<if test="forUpdate != null">
may work.
In java HashMap.get(key) return null when key doesn't exist in map.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With