From e9f99c6c091121e42dda783e7580102acfe55d50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=89=E5=B0=BC?= <544654811@qq.com> Date: Mon, 18 Sep 2017 13:23:50 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[Feature]=20=E5=A2=9E=E5=8A=A0=E9=80=9A?= =?UTF-8?q?=E7=94=A8=E6=9F=A5=E8=AF=A2=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wxiaoqi/security/common/util/Query.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 ace-common/src/main/java/com/github/wxiaoqi/security/common/util/Query.java diff --git a/ace-common/src/main/java/com/github/wxiaoqi/security/common/util/Query.java b/ace-common/src/main/java/com/github/wxiaoqi/security/common/util/Query.java new file mode 100644 index 00000000..e34f8c31 --- /dev/null +++ b/ace-common/src/main/java/com/github/wxiaoqi/security/common/util/Query.java @@ -0,0 +1,45 @@ + +package com.github.wxiaoqi.security.common.util; + + +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * 查询参数 + */ +public class Query extends LinkedHashMap { + private static final long serialVersionUID = 1L; + //当前页码 + private int page = 1; + //每页条数 + private int limit = 10; + + public Query(Map params){ + this.putAll(params); + //分页参数 + if(params.get("page")!=null) + this.page = Integer.parseInt(params.get("page").toString()); + if(params.get("limit")!=null) + this.limit = Integer.parseInt(params.get("limit").toString()); + this.remove("page"); + this.remove("limit"); + } + + + public int getPage() { + return page; + } + + public void setPage(int page) { + this.page = page; + } + + public int getLimit() { + return limit; + } + + public void setLimit(int limit) { + this.limit = limit; + } +} \ No newline at end of file -- Gitee From bd53bf487fdd958ca1cb2035f8e4469977a9e8cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=89=E5=B0=BC?= <544654811@qq.com> Date: Mon, 18 Sep 2017 13:56:35 +0800 Subject: [PATCH 2/2] =?UTF-8?q?[Feature]=20=E5=A2=9E=E5=8A=A0=E9=80=9A?= =?UTF-8?q?=E7=94=A8=E5=88=86=E9=A1=B5=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ace-common/pom.xml | 20 ++++---- .../wxiaoqi/security/common/biz/BaseBiz.java | 51 ++++++++++--------- .../common/msg/TableResultResponse.java | 5 ++ ace-gate/pom.xml | 7 +-- 4 files changed, 44 insertions(+), 39 deletions(-) diff --git a/ace-common/pom.xml b/ace-common/pom.xml index 8ba693c7..7c6de033 100644 --- a/ace-common/pom.xml +++ b/ace-common/pom.xml @@ -33,11 +33,6 @@ javax.servlet-api 3.1.0 - - javax.servlet - javax.servlet-api - 3.1.0 - org.springframework spring-webmvc @@ -63,11 +58,16 @@ jjwt 0.7.0 - - - - - + + com.github.pagehelper + pagehelper + 4.1.1 + + + org.mybatis + mybatis + 3.3.1 + diff --git a/ace-common/src/main/java/com/github/wxiaoqi/security/common/biz/BaseBiz.java b/ace-common/src/main/java/com/github/wxiaoqi/security/common/biz/BaseBiz.java index 7b15a2de..8b8acf19 100644 --- a/ace-common/src/main/java/com/github/wxiaoqi/security/common/biz/BaseBiz.java +++ b/ace-common/src/main/java/com/github/wxiaoqi/security/common/biz/BaseBiz.java @@ -1,23 +1,32 @@ package com.github.wxiaoqi.security.common.biz; +import com.github.pagehelper.Page; +import com.github.pagehelper.PageHelper; +import com.github.wxiaoqi.security.common.msg.TableResultResponse; import com.github.wxiaoqi.security.common.util.EntityUtils; +import com.github.wxiaoqi.security.common.util.Query; import org.springframework.beans.factory.annotation.Autowired; import tk.mybatis.mapper.common.Mapper; import tk.mybatis.mapper.common.example.SelectByExampleMapper; import tk.mybatis.mapper.common.example.SelectCountByExampleMapper; +import tk.mybatis.mapper.entity.Example; +import java.lang.reflect.ParameterizedType; import java.util.List; +import java.util.Map; /** - * Created by zhw - * Date: 17/1/13 + * Created by Mr.AG + * Date: 17/9/18 * Time: 15:13 * Version 1.0.0 + * @uthor 安妮 */ public abstract class BaseBiz, T> { @Autowired protected M mapper; - public void setMapper(M mapper){ + + public void setMapper(M mapper) { this.mapper = mapper; } @@ -31,11 +40,6 @@ public abstract class BaseBiz, T> { } -// public List selectListByIds(List ids) { -// return mapper.selectByIds(ids); -// } - - public List selectList(T entity) { return mapper.select(entity); } @@ -46,11 +50,6 @@ public abstract class BaseBiz, T> { } -// public Long selectCountAll() { -// return mapper.selectCount(null); -// } - - public Long selectCount(T entity) { return new Long(mapper.selectCount(entity)); } @@ -63,7 +62,7 @@ public abstract class BaseBiz, T> { public void insertSelective(T entity) { - EntityUtils.setCreateInfo(entity); + EntityUtils.setCreatAndUpdatInfo(entity); mapper.insertSelective(entity); } @@ -89,19 +88,25 @@ public abstract class BaseBiz, T> { mapper.updateByPrimaryKeySelective(entity); } - public List selectByExample(Object example){ + + public List selectByExample(Object example) { return mapper.selectByExample(example); } - public int selectCountByExample(Object example){ + + public int selectCountByExample(Object example) { return mapper.selectCountByExample(example); } -// public void deleteBatchByIds(List ids) { -// mapper.batchDeleteByIds(ids); -// } - -// public void updateBatch(List entitys) { -// mapper.batchUpdate(entitys); -// } + public TableResultResponse selectByQuery(Query query) { + Class clazz = (Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[1]; + Example example = new Example(clazz); + Example.Criteria criteria = example.createCriteria(); + for (Map.Entry entry : query.entrySet()) { + criteria.andLike(entry.getKey(), "%" + entry.getValue().toString() + "%"); + } + Page result = PageHelper.startPage(query.getPage(), query.getLimit()); + List list = mapper.selectByExample(example); + return new TableResultResponse(result.getTotal(), list); + } } diff --git a/ace-common/src/main/java/com/github/wxiaoqi/security/common/msg/TableResultResponse.java b/ace-common/src/main/java/com/github/wxiaoqi/security/common/msg/TableResultResponse.java index d8034239..b294356a 100644 --- a/ace-common/src/main/java/com/github/wxiaoqi/security/common/msg/TableResultResponse.java +++ b/ace-common/src/main/java/com/github/wxiaoqi/security/common/msg/TableResultResponse.java @@ -17,6 +17,11 @@ public class TableResultResponse { this.rows = rows; } + public TableResultResponse(Long total, List rows) { + this.total = total.intValue(); + this.rows = rows; + } + public TableResultResponse() { } diff --git a/ace-gate/pom.xml b/ace-gate/pom.xml index 7a9a42ca..6c88ef18 100644 --- a/ace-gate/pom.xml +++ b/ace-gate/pom.xml @@ -59,12 +59,7 @@ org.springframework.boot - spring-boot-starter-redis - - - com.github.wxiaoqi - ace-api - 1.0-SNAPSHOT + spring-boot-starter-data-redis com.alibaba -- Gitee