4.查询函数有多个参数
public List<People> queryPeople(String username,String password)
1)在映射文件里,省略parameterType
<select id="queryPeople" resultType="entity的全限定名">
select * from people where username=#{0} and password=#{1}
</select>
通过参数在参数表里的下标指定参数顺序
2)在函数定义上通过“注解”为参数指定固定的名字
public List<People> queryPeople(@Param(value="a1")String username,@Param(value="a2")String password);
<select id="queryPeople" resultType="entity的全限定名">
select * from people where username=#{a1} and password=#{a2}
</select>
5.分页查询 (oracle)
在使用mybatis 时我们sql是写在xml 映射文件中,如果写的sql中有一些特殊的字符的话,在解析xml文件的时候会被转义
如果在sql中包含 > <,sql解析时,特殊符号会发生转义。
解决方案1:使用<![CDATA[….]]> 块
<select id="page" resultType="account"">
<![CDATA[
select card_id as cardId,username,password,age from
(select card_id,usename,password,age,rownum rn from
(select card_id,username,password,age from t_account order by card_id)) e
where e.rn>=#{start} and e.rn<=#{end}
]]>
</select>
解决方案2 :使用转义字符 > 代替> < 代替 <
<select id="page" resultType="account"">
select card_id as cardId,username,password,age from
(select card_id,usename,password,age,rownum rn from
(select card_id,username,password,age from t_account order by card_id)) e
where e.rn >=#{start} and e.rn <=#{end}
</select>
六、除了查询以外呢我们还有其他三种操作
函数定义 -- public void insertPeople(People p); --> p对象的id为null,插入前先获取id值
<insert id="insertPeople" parameterType="实体的全限定名">
<!-- 在执行insert命令前,先获取一个唯一值,给id属性赋值 返回值类型是序列的类型 -->
<selectKey resultType="int" keyProperty="需要被赋值的属性名"
order="BEFORE(本次查询优先于insert命令执行)">
select people_seq.nextval from dual
</selectKey>
insert into people values(#{id},#{参数对象对应的属性名},#{属性名},.....)
</insert>
更新<update>
<update id="update" parameterType="实体全限定名">
update employee set name=#{name}, age=#{age}, salary=#{salary} where id=#{id}
</update>
删除<delete>
<delete id="delete" parameterType="java.lang.Integer">
delete from employee where id = #{id}
</delete>
mybatis的基本用法基本上介绍完了。你学会了吗,敬请期待下一篇的非诚勿扰《mybatis》之在判断