Question

I have a DAO method which accepts as a parameter a HashMap.

The key in the HashMap is the name of the column to be searched.

The String[] contains the potential values to be searched for.

If the String array is of length 1, the where clause matches the exact value in the string array. If the String array is of length 2, the where clause looks for all values BETWEEN the two values in the string array.

Ibatis does not seem to have a mechanism for determining the length of an array in the sqlMap xml file (since length of arrays does not have a JavaBean getter/setter).

Is it possible in ibatis to conditionally detect the length of the string array and adjust the query to either an exact match or a BETWEEN statement?

For example, if the key is age and the value is 18, then all 18 year old users are returned. However, if the key is age and the values are 18 and 23, then all users between 18 and 23 are returned.

The isEqual tag initially looked quite promising, but it does not work with array.length since it does not have a getter/setter. Can ibatis determine the length of an array in the sqlMap?

Thanks.

Was it helpful?

Solution

I wrote some java code to convert my HashMap to have a List instead of String[] and ibatis worked much better with the List.size method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top