I have a query mapper like the following:
<select id="searchSomething" parameterType="SomeType" resultType="SomeOtherType">
select xxxxx
from T_XXXX
where 1=1
<if test="propertyName == 'userName'">
and USER_NAME = #{propertyValue}
</if>
<if test="propertyName == 'address'">
and ADDRESS = #{propertyValue}
</if>
<if test="propertyName == 'taskDate'">
and TASK_DATE = #{propertyValue}
</if>
<if test="propertyName == 'phone1'">
and PHONE_1 = #{propertyValue}
</if>
<if test="propertyName == 'phone2'">
and PHONE_2 = #{propertyValue}
</if>
...
</select>
There are so many properties. How can i simply map the property name to column name, like the following:
<select id="searchSomething" parameterType="SomeType" resultType="SomeOtherType">
select xxxxx
from T_XXXX
where 1=1
and
<propertyToColumn property="propertyName" />
= #{propertyValue}
</select>
Is there something like “propertyToColumn” in MyBatis?
I found “insertColumnName” in iBatis, is it removed from MyBatis?
The parameterType is a java class like:
public class SomeType{
private String propertyName;
private String propertyValue;
... getters and setters
}
I think that it could be better if you do the “parameter-column” conversion in your code, and pass the result column as parameter. In that case you could do something like this:
Of course, you will need to add the propertyColumn to your VO.