当传入多个文件时,mapper接口文件的方法参数要使用@param(“xx”)注释。
例子:
mapper:
//Student是对象,age是String类型。
int getPojo(@param("student") Student student, @param("age") String age );
xml:
<select id="getStudent" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from student
where 1 = 1
<!-- 使用参数一(是个自己的对象) -->
<if test="student.id != null">
and id = #{student.id}
</if>
<!-- 使用参数二 String类型 -->
<if test="age!= null">
and age = #{age}
</if>
</select>
MyBatis多参数传递
本文详细介绍了在MyBatis中如何正确地处理和传递多个参数到Mapper接口和XML配置文件中,通过示例展示了如何使用@param注释来区分不同类型的参数,并在XML中如何动态构建SQL语句。
890

被折叠的 条评论
为什么被折叠?



