引用mybatis-generator-core-1.3.2.jar逆向工程生成pojo、mapper映射文件无分页功能,使用分页修改如下:
在对应Example类中添加属性
protected int offset;
protected int limit;
public int getOffset() {
return offset;
}
public void setOffset(int offset) {
this.offset = offset;
}
public int getLimit() {
return limit;
}
public void setLimit(int limit) {
this.limit = limit;
}
对应mapper.xml映射文件中,selectByExample标签中添加
<if test="offset != null && limit != null && limit!=0">
limit ${offset},${limit}
</if>
整体selectByExample预览如下
<select id="selectByExample" resultMap="BaseResultMap" parameterType="com.yfy.pojo.CustomerExample" >
select
<if test="distinct" >
distinct
</if>
<include refid="Base_Column_List" />
from customer
<if test="_parameter != null" >
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null" >
order by ${orderByClause}
</if>
<if test="offset != null && limit != null && limit!=0">
limit ${offset},${limit}
</if>
</select>
调用的时候设置相应的Example类的limit offset属性即可,亲测有效。
CustomerExample customerExample = new CustomerExample();
customerExample.setOffset(0);
customerExample.setLimit(5);
customerMapper.selectByExample(customerExample);