@Paging XML分页注解
说明
@Paging 是为了解决xml 查询自动分页,它还支持mybatis @Select注解 自动分页
如何用 ?
xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mybatis.mp.core.test.mapper.SysRoleMapper">
<resultMap id="sysRole" type="com.mybatis.mp.core.test.DO.SysRole">
<id column="id" property="id"/>
</resultMap>
<select id="xmlPaging">
select *
from sys_role
where id >= #{id}
and id <= #{id2}
order by id asc
</select>
<select id="xmlPaging2" resultMap="sysRole">
select *
from sys_role
order by id asc
</select>
<select id="xmlDynamicPaging" resultType="com.mybatis.mp.core.test.DO.SysRole">
select * from sys_role where id >=#{id} and id <=#{id2}
<if test="id3 != null">
and id <=#{id3}
</if>
order by id asc
</select>
</mapper>
java
public interface SysRoleMapper extends MybatisMapper<SysRole> {
@Paging
Pager<SysRole> xmlPaging(Pager<SysRole> pager, @Param("id") Integer id, @Param("id2") Integer id2);
@Paging
Pager<SysRole> xmlPaging2(Pager<SysRole> pager);
@Paging
Pager<SysRole> xmlDynamicPaging(Pager<SysRole> pager, @Param("id") Integer id, @Param("id2") Integer id2, @Param("id3") Integer id3);
@Paging
@Select("select * from sys_role where id >=#{id} and id <=#{id2} order by id asc")
Pager<SysRole> annotationPaging(Pager<SysRole> pager, @Param("id") Integer id, @Param("id2") Integer id2);
}
java
Pager<SysRole> pager = sysRoleMapper.xmlPaging(Pager.of(1), 1, 1);
pager = sysRoleMapper.xmlPaging2(Pager.of(2));
pager = xmlDynamicPaging.xmlPaging2(Pager.of(1), 1, 2,3);
pager = annotationPaging.xmlPaging2(Pager.of(1), 1, 2);
使用和普通mapper没区别