您的位置:首页 > 其它

Mybatis中可以传递的参数

2014-04-02 10:22 323 查看
在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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: