MyBatis generator使用,为Example添加分页

版权声明:借鉴时注明出处就行 https://blog.csdn.net/weixin_42144379/article/details/88556774

条件: 数据库为 MySQL

1.对应的 XXXExample.java 中添加两个属性,以及对于的 getter 和 setter 方法

	protected int startRow;

	protected int pageSize;
	

	public int getStartRow() {
		return startRow;
	}

	public void setStartRow(int startRow) {
		this.startRow = startRow;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

2.对应的xxxMapper.xml文件, id为selectByExample 的</select>语句前加上

<if test="startRow != null and pageSize != null and pageSize != 0">
        limit #{startRow},#{pageSize}
    </if>

3.调用的时候 xxxExample的实例 调用 startRow 和 pageSize 的 setter方法

猜你喜欢

转载自blog.csdn.net/weixin_42144379/article/details/88556774