public class PageBase{
private int page ;
private int distance;
private int total;
private int isPage;
private int begen ;
public PageBase(){
this.isPage = 1;
this.page = 1;
this.distance = 7;
this.begen = (this.page-1)*this.distance;
}
public int getPage() {
return page;
}
public void setPage(int page) {
this.begen = (page-1)*this.distance;
this.page = page;
}
public int getDistance() {
return distance;
}
public void setDistance(int distance) {
this.begen = (page-1)*distance;
this.distance = distance;
}
public int getIsPage() {
return isPage;
}
public void setIsPage(int isPage) {
this.isPage = isPage;
}
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
public int getBegen() {
return begen;
}
public void setBegen(int begen) {
this.begen = begen;
}
}
sql
<select id="titles" resultType="util">
select
id,title,date,photos,content
<if test="isPage != 0">
,(select count(*) from gam_help where 1=1
<if test="title != null and title != ''">and title like concat(concat('%',#{title}),'%')</if>
) as total
</if>
from gam_help where 1=1 <if test="title != null and title != ''">and title like concat(concat('%',#{title}),'%')</if>
order by date desc
<if test="isPage != 0">
limit #{begen},#{distance}
</if>
</select>