Use MyBatis-generator to add paging to Example

The database is MySQL .
1. In the Example class, add two variables, startRow and pageSize, which represent the starting index and page capacity respectively, and then generate setter and getter methods.

    /**
     * Pagination parameters: start line
     */
    private Integer startRow;

    /**
     * Paging parameters: paging size
     */
    private Integer pageSize;

    public Integer getStartRow() {
        return startRow;
    }

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

    public Integer getPageSize() {
        return pageSize;
    }

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

 
2. In the corresponding XXXMapper.xml file, add the following to the end of the <select></select> tag pair whose select id is "selectByExample":

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

 Since startRow can be 0, do not set startRow != 0.

3. When using Example to query, just set the values ​​of startRow and pageSize directly.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326290529&siteId=291194637