在MyBatis中,可以使用Map类型作为参数来进行多字段查询。具体步骤如下:
List<User> selectUserByFields(Map<String, Object> map);
<select id="selectUserByFields" parameterType="map" resultType="User">
SELECT * FROM user
<where>
<if test="field1 != null">
AND field1 = #{field1}
</if>
<if test="field2 != null">
AND field2 = #{field2}
</if>
<!-- 其他字段条件 -->
</where>
</select>
Map<String, Object> map = new HashMap<>();
map.put("field1", value1);
map.put("field2", value2);
List<User> users = userMapper.selectUserByFields(map);
通过以上步骤,就可以实现在MyBatis中进行多字段查询。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:mongodb多字段查询的方法是什么