Mybatis中可以傳遞的參數

在mybatis中通常會接受參數,來根據參數限定一些操作數據庫語句。傳遞的參數分類:

1.基本的參數String,int,Date等。在sql語句中通過#(參數名)獲取到參數

<select id="selectPeople" parameterType="int" resultType="com.entry.people">

select * from people where p_id = #{pid}  

</select> 

   2.複雜數據類型:包含JAVA實體類、Map。通過 #{屬性名} 或 #{map的Key值}即可獲取傳入的值

1)java實體類參數傳值

<select id="selectPeople" parameterType="com.entry.people" resultType = "com.entry.people">

select * from people where p_sid = #{pid}

</select>

2) map集合

Map<String,Object> map = new <String,Object> HashMap();

map.put("age",12);

map.put("sex","男");

<select id="selectPeople" parameterType="com.entry.people" resultType = "com.entry.people">

select * from people where p_age = #(age} ande p_sex = #{sex}

</select>


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