Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to test the existence of a parameter in the parameter map?

Tags:

mybatis

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>
like image 894
avalori Avatar asked Jul 31 '13 10:07

avalori


2 Answers

You can use this test:

<if test="_parameter.containsKey('forUpdate')">your code....</if> 
like image 108
Andriy Lobashchuk Avatar answered Oct 29 '22 13:10

Andriy Lobashchuk


<if test="forUpdate != null">

may work.

In java HashMap.get(key) return null when key doesn't exist in map.

like image 22
Larry.Z Avatar answered Oct 29 '22 12:10

Larry.Z