0
我有一张表格,其中包含一些字段以及该表格的一些搜索表单。 我想添加使用此表格筛选表格中项目的功能。 为了实现这一点,我想从表中选择从参数中获取的表格。使用mybatis实现过滤的最佳方式
但问题是什么是使用MyBatis及其XML映射器实现它的最佳方式是什么?
我不喜欢我的解决方案,因为如果有多达10个参数 - 查询将是巨大的......
<select id="getFilteredDevelopers" parameterType="map" resultMap="DeveloperResult">
select
developer_id,
private_information
from pmc.developer
<choose>
<when test="filterId != null and filterPrivateInformation == null">
where developer_id like #{filterId}
</when>
<when test="filterId != null and filterPrivateInformation != null">
where developer_id like #{filterId} and private_information like #{filterPrivateInformation}
</when>
<when test="filterId == null and filterPrivateInformation != null">
where private_information like #{filterPrivateInformation}
</when>
</choose>
</select>
可能只是一个小的改变,但是,您可以用“”替换“Where TRUE”部分,然后在之后关闭标签。 –
yalpertem