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>


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