使用分页插件生成dao代码

This commit is contained in:
shuzheng 2016-10-17 14:37:40 +08:00
parent 8743d01bff
commit 7f934f06ce
32 changed files with 476 additions and 353 deletions

View File

@ -45,6 +45,13 @@
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<dependencies>
<dependency>
<groupId>com.zheng</groupId>
<artifactId>common</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<configuration>
<verbose>true</verbose>
<overwrite>true</overwrite>

View File

@ -1,77 +0,0 @@
package com.zheng.cms.interceptor;
import java.sql.Connection;
import java.util.Map;
import java.util.Properties;
import org.apache.ibatis.executor.statement.StatementHandler;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Plugin;
import org.apache.ibatis.plugin.Signature;
import org.apache.ibatis.reflection.MetaObject;
import org.apache.ibatis.reflection.SystemMetaObject;
import com.zheng.cms.util.Paginator;
/**
* 分页拦截器
* @author shuzheng
* @date 2016年7月6日 下午6:04:12
*/
@Intercepts({
@Signature(
type = StatementHandler.class,
method = "prepare",
args = {Connection.class }
)
})
public class PageInterceptor implements Interceptor {
private String pageSqlId;
@Override
public Object intercept(Invocation invocation) throws Throwable {
// 拦截的对象
StatementHandler statementHandler = (StatementHandler) invocation.getTarget();
// 通过反射拿到拦截对象的sqlid
MetaObject metaObject = MetaObject.forObject(statementHandler, SystemMetaObject.DEFAULT_OBJECT_FACTORY, SystemMetaObject.DEFAULT_OBJECT_WRAPPER_FACTORY);
MappedStatement mappedStatement = (MappedStatement) metaObject.getValue("delegate.mappedStatement");
// 配置文件中SQL语句的ID
String id = mappedStatement.getId();
// 如果SQL的ID符合我们的过滤正则表达式
if (id.matches(pageSqlId)) {
BoundSql boundSql = statementHandler.getBoundSql();
// 原始的SQL语句
String sql = boundSql.getSql();
Map<?, ?> parameter = (Map<?, ?>) boundSql.getParameterObject();
// 有参数对象才能进行
if (parameter != null) {
Paginator paginator = (Paginator) parameter.get("paginator");
// 有分页对象则改造为带分页查询的SQL语句
if (paginator != null) {
String pageSql = sql + " limit " + (paginator.getPage() - 1) * paginator.getRows() + "," + paginator.getRows();
metaObject.setValue("delegate.boundSql.sql", pageSql);
}
}
}
return invocation.proceed();
}
@Override
public Object plugin(Object target) {
// 拦截的对象是否需要代理如果是则执行intercept方法增强不是则直接放行
return Plugin.wrap(target, this);
}
@Override
public void setProperties(Properties properties) {
// 初始化拦截器的配置
this.pageSqlId = properties.getProperty("pageSqlId");
}
}

View File

@ -80,6 +80,14 @@
<if test="orderByClause != null" >
order by ${orderByClause}
</if>
<if test="limit != null" >
<if test="offset != null" >
limit ${offset}, ${limit}
</if>
<if test="offset == null" >
limit ${limit}
</if>
</if>
</select>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select

View File

@ -80,6 +80,14 @@
<if test="orderByClause != null" >
order by ${orderByClause}
</if>
<if test="limit != null" >
<if test="offset != null" >
limit ${offset}, ${limit}
</if>
<if test="offset == null" >
limit ${limit}
</if>
</if>
</select>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select

View File

@ -116,6 +116,14 @@
<if test="orderByClause != null" >
order by ${orderByClause}
</if>
<if test="limit != null" >
<if test="offset != null" >
limit ${offset}, ${limit}
</if>
<if test="offset == null" >
limit ${limit}
</if>
</if>
</select>
<select id="selectByPrimaryKey" resultMap="ResultMapWithBLOBs" parameterType="java.lang.Integer" >
select

View File

@ -80,6 +80,14 @@
<if test="orderByClause != null" >
order by ${orderByClause}
</if>
<if test="limit != null" >
<if test="offset != null" >
limit ${offset}, ${limit}
</if>
<if test="offset == null" >
limit ${limit}
</if>
</if>
</select>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select

View File

@ -87,6 +87,14 @@
<if test="orderByClause != null" >
order by ${orderByClause}
</if>
<if test="limit != null" >
<if test="offset != null" >
limit ${offset}, ${limit}
</if>
<if test="offset == null" >
limit ${limit}
</if>
</if>
</select>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select

View File

@ -80,6 +80,14 @@
<if test="orderByClause != null" >
order by ${orderByClause}
</if>
<if test="limit != null" >
<if test="offset != null" >
limit ${offset}, ${limit}
</if>
<if test="offset == null" >
limit ${limit}
</if>
</if>
</select>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select

View File

@ -107,6 +107,14 @@
<if test="orderByClause != null" >
order by ${orderByClause}
</if>
<if test="limit != null" >
<if test="offset != null" >
limit ${offset}, ${limit}
</if>
<if test="offset == null" >
limit ${limit}
</if>
</if>
</select>
<select id="selectByPrimaryKey" resultMap="ResultMapWithBLOBs" parameterType="java.lang.Integer" >
select

View File

@ -85,6 +85,14 @@
<if test="orderByClause != null" >
order by ${orderByClause}
</if>
<if test="limit != null" >
<if test="offset != null" >
limit ${offset}, ${limit}
</if>
<if test="offset == null" >
limit ${limit}
</if>
</if>
</select>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select

View File

@ -105,6 +105,14 @@
<if test="orderByClause != null" >
order by ${orderByClause}
</if>
<if test="limit != null" >
<if test="offset != null" >
limit ${offset}, ${limit}
</if>
<if test="offset == null" >
limit ${limit}
</if>
</if>
</select>
<select id="selectByPrimaryKey" resultMap="ResultMapWithBLOBs" parameterType="java.lang.Integer" >
select

View File

@ -1,12 +1,16 @@
package com.zheng.cms.model;
public class Book {
import java.io.Serializable;
public class Book implements Serializable {
private Integer id;
private Integer userid;
private String name;
private static final long serialVersionUID = 1L;
public Integer getId() {
return id;
}
@ -30,4 +34,17 @@ public class Book {
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", userid=").append(userid);
sb.append(", name=").append(name);
sb.append("]");
return sb.toString();
}
}

View File

@ -10,6 +10,10 @@ public class BookExample {
protected List<Criteria> oredCriteria;
private Integer limit;
private Integer offset;
public BookExample() {
oredCriteria = new ArrayList<Criteria>();
}
@ -63,6 +67,22 @@ public class BookExample {
distinct = false;
}
public void setLimit(Integer limit) {
this.limit = limit;
}
public Integer getLimit() {
return limit;
}
public void setOffset(Integer offset) {
this.offset = offset;
}
public Integer getOffset() {
return offset;
}
protected abstract static class GeneratedCriteria {
protected List<Criterion> criteria;

View File

@ -1,6 +1,8 @@
package com.zheng.cms.model;
public class CmsArticle {
import java.io.Serializable;
public class CmsArticle implements Serializable {
private Integer articleId;
private String title;
@ -35,6 +37,8 @@ public class CmsArticle {
private String content;
private static final long serialVersionUID = 1L;
public Integer getArticleId() {
return articleId;
}
@ -170,4 +174,31 @@ public class CmsArticle {
public void setContent(String content) {
this.content = content;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", articleId=").append(articleId);
sb.append(", title=").append(title);
sb.append(", author=").append(author);
sb.append(", fromurl=").append(fromurl);
sb.append(", image=").append(image);
sb.append(", keywords=").append(keywords);
sb.append(", description=").append(description);
sb.append(", type=").append(type);
sb.append(", allowcomments=").append(allowcomments);
sb.append(", status=").append(status);
sb.append(", userId=").append(userId);
sb.append(", up=").append(up);
sb.append(", down=").append(down);
sb.append(", readnumber=").append(readnumber);
sb.append(", ctime=").append(ctime);
sb.append(", orders=").append(orders);
sb.append(", content=").append(content);
sb.append("]");
return sb.toString();
}
}

View File

@ -1,12 +1,16 @@
package com.zheng.cms.model;
public class CmsArticleCategory {
import java.io.Serializable;
public class CmsArticleCategory implements Serializable {
private Integer articleCategoryId;
private Integer articleId;
private Integer categoryId;
private static final long serialVersionUID = 1L;
public Integer getArticleCategoryId() {
return articleCategoryId;
}
@ -30,4 +34,17 @@ public class CmsArticleCategory {
public void setCategoryId(Integer categoryId) {
this.categoryId = categoryId;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", articleCategoryId=").append(articleCategoryId);
sb.append(", articleId=").append(articleId);
sb.append(", categoryId=").append(categoryId);
sb.append("]");
return sb.toString();
}
}

View File

@ -10,6 +10,10 @@ public class CmsArticleCategoryExample {
protected List<Criteria> oredCriteria;
private Integer limit;
private Integer offset;
public CmsArticleCategoryExample() {
oredCriteria = new ArrayList<Criteria>();
}
@ -63,6 +67,22 @@ public class CmsArticleCategoryExample {
distinct = false;
}
public void setLimit(Integer limit) {
this.limit = limit;
}
public Integer getLimit() {
return limit;
}
public void setOffset(Integer offset) {
this.offset = offset;
}
public Integer getOffset() {
return offset;
}
protected abstract static class GeneratedCriteria {
protected List<Criterion> criteria;

View File

@ -10,6 +10,10 @@ public class CmsArticleExample {
protected List<Criteria> oredCriteria;
private Integer limit;
private Integer offset;
public CmsArticleExample() {
oredCriteria = new ArrayList<Criteria>();
}
@ -63,6 +67,22 @@ public class CmsArticleExample {
distinct = false;
}
public void setLimit(Integer limit) {
this.limit = limit;
}
public Integer getLimit() {
return limit;
}
public void setOffset(Integer offset) {
this.offset = offset;
}
public Integer getOffset() {
return offset;
}
protected abstract static class GeneratedCriteria {
protected List<Criterion> criteria;

View File

@ -1,12 +1,16 @@
package com.zheng.cms.model;
public class CmsArticleTag {
import java.io.Serializable;
public class CmsArticleTag implements Serializable {
private Integer articleTagId;
private Integer articleId;
private Integer tagId;
private static final long serialVersionUID = 1L;
public Integer getArticleTagId() {
return articleTagId;
}
@ -30,4 +34,17 @@ public class CmsArticleTag {
public void setTagId(Integer tagId) {
this.tagId = tagId;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", articleTagId=").append(articleTagId);
sb.append(", articleId=").append(articleId);
sb.append(", tagId=").append(tagId);
sb.append("]");
return sb.toString();
}
}

View File

@ -10,6 +10,10 @@ public class CmsArticleTagExample {
protected List<Criteria> oredCriteria;
private Integer limit;
private Integer offset;
public CmsArticleTagExample() {
oredCriteria = new ArrayList<Criteria>();
}
@ -63,6 +67,22 @@ public class CmsArticleTagExample {
distinct = false;
}
public void setLimit(Integer limit) {
this.limit = limit;
}
public Integer getLimit() {
return limit;
}
public void setOffset(Integer offset) {
this.offset = offset;
}
public Integer getOffset() {
return offset;
}
protected abstract static class GeneratedCriteria {
protected List<Criterion> criteria;

View File

@ -1,6 +1,8 @@
package com.zheng.cms.model;
public class CmsCategory {
import java.io.Serializable;
public class CmsCategory implements Serializable {
private Integer categoryId;
private Integer pid;
@ -21,6 +23,8 @@ public class CmsCategory {
private Long orders;
private static final long serialVersionUID = 1L;
public Integer getCategoryId() {
return categoryId;
}
@ -100,4 +104,24 @@ public class CmsCategory {
public void setOrders(Long orders) {
this.orders = orders;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", categoryId=").append(categoryId);
sb.append(", pid=").append(pid);
sb.append(", level=").append(level);
sb.append(", name=").append(name);
sb.append(", description=").append(description);
sb.append(", icon=").append(icon);
sb.append(", type=").append(type);
sb.append(", alias=").append(alias);
sb.append(", ctime=").append(ctime);
sb.append(", orders=").append(orders);
sb.append("]");
return sb.toString();
}
}

View File

@ -10,6 +10,10 @@ public class CmsCategoryExample {
protected List<Criteria> oredCriteria;
private Integer limit;
private Integer offset;
public CmsCategoryExample() {
oredCriteria = new ArrayList<Criteria>();
}
@ -63,6 +67,22 @@ public class CmsCategoryExample {
distinct = false;
}
public void setLimit(Integer limit) {
this.limit = limit;
}
public Integer getLimit() {
return limit;
}
public void setOffset(Integer offset) {
this.offset = offset;
}
public Integer getOffset() {
return offset;
}
protected abstract static class GeneratedCriteria {
protected List<Criterion> criteria;

View File

@ -1,12 +1,16 @@
package com.zheng.cms.model;
public class CmsCategoryTag {
import java.io.Serializable;
public class CmsCategoryTag implements Serializable {
private Integer categoryTagId;
private Integer categoryId;
private Integer tagId;
private static final long serialVersionUID = 1L;
public Integer getCategoryTagId() {
return categoryTagId;
}
@ -30,4 +34,17 @@ public class CmsCategoryTag {
public void setTagId(Integer tagId) {
this.tagId = tagId;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", categoryTagId=").append(categoryTagId);
sb.append(", categoryId=").append(categoryId);
sb.append(", tagId=").append(tagId);
sb.append("]");
return sb.toString();
}
}

View File

@ -10,6 +10,10 @@ public class CmsCategoryTagExample {
protected List<Criteria> oredCriteria;
private Integer limit;
private Integer offset;
public CmsCategoryTagExample() {
oredCriteria = new ArrayList<Criteria>();
}
@ -63,6 +67,22 @@ public class CmsCategoryTagExample {
distinct = false;
}
public void setLimit(Integer limit) {
this.limit = limit;
}
public Integer getLimit() {
return limit;
}
public void setOffset(Integer offset) {
this.offset = offset;
}
public Integer getOffset() {
return offset;
}
protected abstract static class GeneratedCriteria {
protected List<Criterion> criteria;

View File

@ -1,6 +1,8 @@
package com.zheng.cms.model;
public class CmsComment {
import java.io.Serializable;
public class CmsComment implements Serializable {
private Integer commentId;
private Integer pid;
@ -19,6 +21,8 @@ public class CmsComment {
private String content;
private static final long serialVersionUID = 1L;
public Integer getCommentId() {
return commentId;
}
@ -90,4 +94,23 @@ public class CmsComment {
public void setContent(String content) {
this.content = content;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", commentId=").append(commentId);
sb.append(", pid=").append(pid);
sb.append(", articleId=").append(articleId);
sb.append(", userId=").append(userId);
sb.append(", status=").append(status);
sb.append(", ip=").append(ip);
sb.append(", agent=").append(agent);
sb.append(", ctime=").append(ctime);
sb.append(", content=").append(content);
sb.append("]");
return sb.toString();
}
}

View File

@ -10,6 +10,10 @@ public class CmsCommentExample {
protected List<Criteria> oredCriteria;
private Integer limit;
private Integer offset;
public CmsCommentExample() {
oredCriteria = new ArrayList<Criteria>();
}
@ -63,6 +67,22 @@ public class CmsCommentExample {
distinct = false;
}
public void setLimit(Integer limit) {
this.limit = limit;
}
public Integer getLimit() {
return limit;
}
public void setOffset(Integer offset) {
this.offset = offset;
}
public Integer getOffset() {
return offset;
}
protected abstract static class GeneratedCriteria {
protected List<Criterion> criteria;

View File

@ -1,6 +1,8 @@
package com.zheng.cms.model;
public class CmsTag {
import java.io.Serializable;
public class CmsTag implements Serializable {
private Integer tagId;
private String name;
@ -17,6 +19,8 @@ public class CmsTag {
private Long orders;
private static final long serialVersionUID = 1L;
public Integer getTagId() {
return tagId;
}
@ -80,4 +84,22 @@ public class CmsTag {
public void setOrders(Long orders) {
this.orders = orders;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", tagId=").append(tagId);
sb.append(", name=").append(name);
sb.append(", description=").append(description);
sb.append(", icon=").append(icon);
sb.append(", type=").append(type);
sb.append(", alias=").append(alias);
sb.append(", ctime=").append(ctime);
sb.append(", orders=").append(orders);
sb.append("]");
return sb.toString();
}
}

View File

@ -10,6 +10,10 @@ public class CmsTagExample {
protected List<Criteria> oredCriteria;
private Integer limit;
private Integer offset;
public CmsTagExample() {
oredCriteria = new ArrayList<Criteria>();
}
@ -63,6 +67,22 @@ public class CmsTagExample {
distinct = false;
}
public void setLimit(Integer limit) {
this.limit = limit;
}
public Integer getLimit() {
return limit;
}
public void setOffset(Integer offset) {
this.offset = offset;
}
public Integer getOffset() {
return offset;
}
protected abstract static class GeneratedCriteria {
protected List<Criterion> criteria;

View File

@ -1,6 +1,8 @@
package com.zheng.cms.model;
public class User {
import java.io.Serializable;
public class User implements Serializable {
private Integer id;
private String username;
@ -15,6 +17,8 @@ public class User {
private String content;
private static final long serialVersionUID = 1L;
public Integer getId() {
return id;
}
@ -70,4 +74,21 @@ public class User {
public void setContent(String content) {
this.content = content;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", username=").append(username);
sb.append(", password=").append(password);
sb.append(", nickname=").append(nickname);
sb.append(", sex=").append(sex);
sb.append(", ctime=").append(ctime);
sb.append(", content=").append(content);
sb.append("]");
return sb.toString();
}
}

View File

@ -10,6 +10,10 @@ public class UserExample {
protected List<Criteria> oredCriteria;
private Integer limit;
private Integer offset;
public UserExample() {
oredCriteria = new ArrayList<Criteria>();
}
@ -63,6 +67,22 @@ public class UserExample {
distinct = false;
}
public void setLimit(Integer limit) {
this.limit = limit;
}
public Integer getLimit() {
return limit;
}
public void setOffset(Integer offset) {
this.offset = offset;
}
public Integer getOffset() {
return offset;
}
protected abstract static class GeneratedCriteria {
protected List<Criterion> criteria;

View File

@ -1,229 +0,0 @@
package com.zheng.cms.util;
/**
* 分页实体类
* @author shuzheng
* @date 2016年7月6日 下午6:05:00
*/
public class Paginator {
private long total = 0l; // 总记录数
private int page = 1; // 当前页数
private long totalPage = 1; // 总页数
private int rows = 10; // 每页记录数
private int step = 5; // 最多显示分页页码数
private String param = "page"; // 分页参数名称用于支持一个页面多个分页功能
private String url = ""; // 项目路径
private String query = ""; // 当前页所有参数
public long getTotal() {
return total;
}
public void setTotal(long total) {
this.total = total;
this.initTotalPage();
}
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
public long getTotalPage() {
return totalPage;
}
public void setTotalPage(long totalPage) {
this.totalPage = totalPage;
}
public int getRows() {
return rows;
}
public void setRows(int rows) {
// 设置个最大记录数限制单页记录过多
if (rows > 10000) {
rows = 10000;
}
this.rows = rows;
this.initTotalPage();
}
public int getStep() {
return step;
}
public void setStep(int step) {
this.step = step;
}
public String getParam() {
return param;
}
public void setParam(String param) {
this.param = param;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getQuery() {
return query;
}
public void setQuery(String query) {
this.query = query;
}
/**
* 初始化分页信息
*/
public void initTotalPage() {
totalPage = (total % rows) == 0 ? (total / rows) : ((total / rows) + 1);
if (page > totalPage) {
page = (int) totalPage;
}
if (page < 1) {
page = 1;
}
}
/**
* 生成简单的分页页面内容
* @return
*/
public String getHtml() {
// 根据request获取当前url包括参数如果有已存在名称未paramname的参数剔除掉后面会追加新的参数
//String contextPath = request.getContextPath();
//String requestURI = request.getRequestURI();
//String url = contextPath + requestURI;
//String url = request.getRequestURI();
//String query = request.getQueryString();
if (query != null) {
String params = "";
String[] querys = query.split("&");
for (int i = 0; i < querys.length; i++) {
if (querys[i].startsWith(param))
continue;
if (params.equals(""))
params += querys[i];
else
params += "&" + querys[i];
}
if (!params.equals(""))
url += "?" + params;
}
// 结果html
String pages = "";
int pageCount = (int) Math.ceil((double) total / rows);// 求总页数
if (pageCount <= 1) {
return pages;
}
if (page > pageCount) {
page = pageCount;// 如果分页变量大总页数则将分页变量设计为总页数
}
if (page <= 0) {
page = 1;// 如果分页变量小于1,则将分页变量设为1
}
// 显示上一页
if (page > 1) {
if (url.contains("?")) {
pages = pages.concat("<a class=\"prev\" href=\"" + url + "&" + param + "=" + (page - 1) + "\">上一页</a>\n");
} else {
pages = pages.concat("<a class=\"prev\" href=\"" + url + "?" + param + "=" + (page - 1) + "\">上一页</a>\n");
}
} else {
// pages =
// pages.concat("<a class=\"prev\" href=\"javascript:;\" style=\"color:#ccc\">上一页</a>\n");
}
// 如果总页数大于要显示的个数则拼接显示
if (pageCount > step) {
// 显示分页码
int listBegin = (page - (int) Math.floor((double) step / 2));// 从第几页开始显示分页信息
if (listBegin < 1) {
listBegin = 1;
}
// 显示第1页
if (listBegin >= 2) {
if (url.contains("?")) {
pages = pages.concat("<a href=\"" + url + "&" + param + "=1\">1</a> ... \n");
} else {
pages = pages.concat("<a href=\"" + url + "?" + param + "=1\">1</a> ... \n");
}
}
// 当前页数右侧还有未显示页码时
if (pageCount - page >= page - listBegin) {
for (int i = listBegin; i < (listBegin + step); i++) {
if (i != page) {
if (url.contains("?")) {
pages = pages.concat("<a href=\"" + url + "&" + param + "=" + i + "\">" + i + "</a>\n");
} else {
pages = pages.concat("<a href=\"" + url + "?" + param + "=" + i + "\">" + i + "</a>\n");
}
} else {
pages = pages.concat("<span class=\"current\">" + i + "</span>\n");
}
}
// 显示最后1页
if (listBegin + step <= pageCount) {
if (url.contains("?")) {
pages = pages.concat(" ... <a href=\"" + url + "&" + param + "=" + pageCount + "\">" + pageCount + "</a>\n");
} else {
pages = pages.concat(" ... <a href=\"" + url + "?" + param + "=" + pageCount + "\">" + pageCount + "</a>\n");
}
}
} else { // 显示最后剩余的几个页码
for (int i = (pageCount - step) + 1; i <= pageCount; i++) {
if (i != page) {
if (url.contains("?")) {
pages = pages.concat("<a href=\"" + url + "&" + param + "=" + i + "\">" + i + "</a>\n");
} else {
pages = pages.concat("<a href=\"" + url + "?" + param + "=" + i + "\">" + i + "</a>\n");
}
} else {
pages = pages.concat("<span class=\"current\">" + i + "</span>\n");
}
}
}
} else { // 总页数小于等于step时直接显示
for (int i = 1; i <= pageCount; i++) {
if (i != page) {
if (url.contains("?")) {
pages = pages.concat("<a href=\"" + url + "&" + param + "=" + i + "\">" + i + "</a>\n");
} else {
pages = pages.concat("<a href=\"" + url + "?" + param + "=" + i + "\">" + i + "</a>\n");
}
} else {
pages = pages.concat("<span class=\"current\">" + i + "</span>\n");
}
}
}
// 显示下一页
if (page < pageCount) {
if (url.contains("?")) {
pages = pages.concat("<a class=\"next\" href=\"" + url + "&" + param + "=" + (page + 1) + "\">下一页</a>\n");
} else {
pages = pages.concat("<a class=\"next\" href=\"" + url + "?" + param + "=" + (page + 1) + "\">下一页</a>\n");
}
} else {
// pages =
// pages.concat("<a class=\"next\" href=\"javascript:;\" style=\"color:#ccc\">下一页</a>\n");
}
return pages;
}
}

View File

@ -6,11 +6,28 @@
<properties resource="jdbc.properties"></properties>
<!-- mysql驱动包 -->
<classPathEntry location="C:\Users\shuzheng\.m2\repository\mysql\mysql-connector-java\5.1.34\mysql-connector-java-5.1.34.jar" />
<classPathEntry location="D:\mysql-connector-java-5.1.34.jar" />
<context id="context" targetRuntime="MyBatis3">
<!-- 去掉注释 -->
<property name="javaFileEncoding" value="UTF-8"/>
<!-- 由于beginningDelimiter和endingDelimiter的默认值为双引号(")在Mysql中不能这么写所以还要将这两个默认值改为**反单引号(`)**,配置如下: -->
<property name="beginningDelimiter" value=""/>
<property name="endingDelimiter" value=""/>
<!-- 为生成的Java模型创建一个toString方法 -->
<plugin type="org.mybatis.generator.plugins.ToStringPlugin"></plugin>
<!-- 为生成的Java模型类添加序列化接口并生成serialVersionUID字段 -->
<plugin type="org.mybatis.generator.plugins.SerializablePlugin">
<property name="suppressJavaInterface" value="false"/>
</plugin>
<!-- 生成一个新的selectByExample方法这个方法可以接受一个RowBounds参数主要用来实现分页 -->
<plugin type="com.zheng.common.plugin.PaginationPlugin"></plugin>
<!-- 生成的代码去掉注释 -->
<commentGenerator>
<property name="suppressAllComments" value="true" />
</commentGenerator>

View File

@ -9,40 +9,4 @@
<package name="com.zheng.cms.model" />
</typeAliases>
<plugins>
<!-- 手写分页拦截器 -->
<plugin interceptor="com.zheng.cms.interceptor.PageInterceptor">
<property name="pageSqlId" value=".*All$" />
</plugin>
<!-- 分页插件 -->
<!-- com.github.pagehelper为PageHelper类所在包名 -->
<plugin interceptor="com.github.pagehelper.PageHelper">
<!-- 4.0.0以后版本可以不设置该参数 -->
<property name="dialect" value="mysql" />
<!-- 该参数默认为false -->
<!-- 设置为true时会将RowBounds第一个参数offset当成pageNum页码使用 -->
<!-- 和startPage中的pageNum效果一样 -->
<property name="offsetAsPageNum" value="true" />
<!-- 该参数默认为false -->
<!-- 设置为true时使用RowBounds分页会进行count查询 -->
<property name="rowBoundsWithCount" value="true" />
<!-- 设置为true时如果pageSize=0或者RowBounds.limit = 0就会查询出全部的结果 -->
<!-- 相当于没有执行分页查询但是返回结果仍然是Page类型 -->
<property name="pageSizeZero" value="true" />
<!-- 3.3.0版本可用 - 分页参数合理化默认false禁用 -->
<!-- 启用合理化时如果pageNum<1会查询第一页如果pageNum>pages会查询最后一页 -->
<!-- 禁用合理化时如果pageNum<1或pageNum>pages会返回空数据 -->
<property name="reasonable" value="false" />
<!-- 3.5.0版本可用 - 为了支持startPage(Object params)方法 -->
<!-- 增加了一个`params`参数来配置参数映射用于从Map或ServletRequest中取值 -->
<!-- 可以配置pageNum,pageSize,count,pageSizeZero,reasonable,orderBy,不配置映射的用默认值 -->
<!-- 不理解该含义的前提下,不要随便复制该配置 -->
<property name="params" value="pageNum=pageHelperStart;pageSize=pageHelperRows;" />
<!-- 支持通过Mapper接口参数来传递分页参数 -->
<property name="supportMethodsArguments" value="false" />
<!-- always总是返回PageInfo类型,check检查返回类型是否为PageInfo,none返回Page -->
<property name="returnPageInfo" value="none" />
</plugin>
</plugins>
</configuration>