Check if parameter exists?

193 views
Skip to first unread message

Stephen Friedrich

unread,
Apr 20, 2012, 11:23:38 AM4/20/12
to mybati...@googlegroups.com
I have a "baseQuery", i.e. a complex piece of sql, that I have put into an <sql> tag for reuse.
That snippet is used as a subquery in many different queries.
To optimize performance I'd like to add a where clause to the baseQuery itself like so:
        <where>
            <if test="projectId != null">
                t.project_id = ${projectId}
            </if>
            <if test="taskId != null">
                and t.id = ${taskId}
            </if>
        </where>
The problem is that neither "projectId" nor "taskId" parameters are present in all queries.
How can I check if the specific query has these parameters?

Eduardo Macarron

unread,
Apr 20, 2012, 11:37:12 AM4/20/12
to mybati...@googlegroups.com
Use _parameter.containsKey(xxx)

El día 20 de abril de 2012 17:23, Stephen Friedrich
<stephen....@fortis-it.de> escribió:

Stephen Friedrich

unread,
Apr 20, 2012, 11:47:18 AM4/20/12
to mybati...@googlegroups.com
Thanks a million! Works perfectly and makes all the difference for my app (10 times speedup for common use cases).

Mike Fotiou

unread,
May 6, 2012, 8:51:56 PM5/6/12
to mybati...@googlegroups.com
Hi Eduardo,

  What is this mysterious "_parameter" value?  Does it represent the parameter map that Mybatis generates when more than one parameter is used in the call to the mapper statement?

Thanks,

Mike

Eduardo Macarron

unread,
May 7, 2012, 12:55:04 AM5/7/12
to mybati...@googlegroups.com
The input parameter is always stored under the key _parameter in the
OGNL context.
Reply all
Reply to author
Forward
0 new messages