mybatis(3) : 逆向工程实现分页查询

1. 打开生成的example.class,在里面的变量中增加offset,limit两个变量,并为其添加set,get方法

    private int start;
    private int count;


    public int getStart() {
		return start;
	}

	public void setStart(int start) {
		this.start = start;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

2. 打开mapper.xml文件里面对应位置设置配置.例如在selectByExample方法中配置,添加条件

<if test="start != null &amp;&amp; count != null">
    	limit ${start},${count}
	</if>

完整sql如下:

<select id="selectByExample" resultMap="BaseResultMap"
		parameterType="com.wanpro.mp.entity.MpAeGroupActivityExample">
		select
		<if test="distinct">
			distinct
		</if>
		<include refid="Base_Column_List" />
		from mp_ae_group_activity
		<if test="_parameter != null">
			<include refid="Example_Where_Clause" />
		</if>
		<if test="orderByClause != null">
			order by ${orderByClause}
		</if>
		<if test="start != null &amp;&amp; count != null">
			limit ${start},${count}
		</if>
	</select>

3. 通过java代码实现具体业务逻辑,实现分页

Example example = new Example();
			//设置分页属性进行分页查询
			example.setStart(start);
			example.setCount(count);
			List lists = mapper.selectByExample(example);

参考 : https://blog.csdn.net/weixin_35891116/article/details/53734795

END

猜你喜欢

转载自blog.csdn.net/Lxinccode/article/details/81239175