MyBatis傳入多個參數

傳入多個參數的方法

  • #{index} 表示第幾個參數

      <update id="updateCourseStudent_id" parameterType="int">
            update course2 set student_id=#{0} where cid=#{1}
      </update>
  • 通過註解

    接口:
    public void updateCourseStudent_id2(@Param("student_id") long sid,@Param("cid") long cid);
    xml:
      <update id="updateCourseStudent_id2" parameterType="long">
            update course2 set student_id=#{student_id} where cid=#{cid}
      </update>
  • 通過Map的方式傳遞

    map中key的名字就是在#{}中使用的那個

    
     <update id="updateCourseStudent_id2" parameterType="long">
            update course2 set student_id=#{key1} where cid=#{key2}
      </update>
  • 創建javaBean,添加get/set,將參數作爲javaBean的屬性

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章