1. 程式人生 > >SSM框架之Mybatis同時傳入多個物件及普通引數

SSM框架之Mybatis同時傳入多個物件及普通引數

當傳入多個檔案時,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>