Search code examples
javasqlibatis

ibatis isNotEmpty with multiple variables


Suppose I have a massive table called inactiveUsers and a search form. I want to conditionally join the inactiveUsers table if any user related characteristic is chosen (address, name, phoneNumber, etc...). Is there any way to do this without the following:

<isNotEmpty property="address">JOIN inactiveUsers</isNotEmpty>
<isNotEmpty property="phoneNumber">JOIN inactiveUsers</isNotEmpty>
<isNotEmpty property="name">JOIN inactiveUsers</isNotEmpty>

and so on for another 10-20 isNotEmpty clauses. I would like to do something like:

<isAnyNotEmpty properties="address, phoneNumber, name, ....">JOIN inactiveUsers</isNotEmpty>

Is this possible with ibatis? If so, how?


Solution

  • I would create a boolean property useJoin

    public boolean isUseJoin() {
            if(!adress.equals("") && !phoneNumber.equals("")&&!name.equals("")) {
                return true;
            } else {
                return false;
            }
        }
    

    not perfect but seems better than multiple statements in IBATIS clause.