From 55334da20cff4dac840c320eda1d0ca53ba27eda Mon Sep 17 00:00:00 2001 From: fwq <582742538@qq.com> Date: 星期一, 23 九月 2024 14:26:36 +0800 Subject: [PATCH] Merge branch 'master-stander' into master-xlk --- src/main/java/com/hx/mybatisTool/SqlSentence.java | 85 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 85 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/hx/mybatisTool/SqlSentence.java b/src/main/java/com/hx/mybatisTool/SqlSentence.java index e0705c9..882a2a9 100644 --- a/src/main/java/com/hx/mybatisTool/SqlSentence.java +++ b/src/main/java/com/hx/mybatisTool/SqlSentence.java @@ -13,7 +13,11 @@ */ public class SqlSentence { + /**鎵ц璇彞*/ private String sqlSentence; + + /**鏂板瀛樺湪鏌ヨ鍒ゆ柇*/ + private String whereExist; private Map<String,Object> m; /**鎺掑簭*/ @@ -22,6 +26,8 @@ private Integer startPage = 0; /**姣忛〉鏁伴噺*/ private Integer pageNum = 0; + /**鏉℃暟锛堝綋鍓嶇被浣跨敤锛�*/ + private Integer pageSize; ////////////////////////////////////////////////////////////// @@ -84,6 +90,66 @@ sqlSentence = sql; m = values; } + + /** + * sql鏁存潯璇彞-鍒嗛〉 + * @param sql 濡傦細select * from user Where name = #{m.userName} order by age desc + * @param values 瀛樻斁鐨勫�煎锛歷alues.put("userName","ChenJiaHe") + * @param pageNum 褰撳墠椤垫暟 + * @param pageSize 褰撳墠鏉℃暟 + */ + public void sqlSentencePage(String sql,Map<String,Object> values,int pageNum,int pageSize) { + if(StringUtils.isEmpty(sql)) { + throw new TipsException("sql is null"); + } + + if(values == null) { + throw new TipsException("values is null"); + } + if(pageNum < 1){ + pageNum = 1; + } + if(pageSize < 1){ + pageSize = 1; + } + this.pageNum = pageNum; + this.pageSize = pageSize; + + //绠楄捣鐐� + int pageStart = (pageNum-1)*pageSize; + sql = sql+" LIMIT "+pageStart+","+pageSize; + sqlSentence = sql; + m = values; + } + + /**鍒嗛〉缁勮淇℃伅 + * @param data 瑁呰浇淇℃伅 + * @param totalNum 鎬婚〉鏁� + * @return 瑁呰浇淇℃伅 + */ + public Map<String,Object> pageAssembleData(Map<String,Object> data,int totalNum){ + data.put("pageNum",pageNum); + data.put("pageSize",pageSize); + data.put("total",totalNum); + int pages; + if(pageSize > 0){ + if(totalNum%pageSize > 0){ + pages = totalNum/pageSize+1; + }else{ + pages = totalNum/pageSize; + } + }else{ + pages = 0; + } + data.put("pages",pages); + if(pages <= pageNum){ + data.put("isLastPage",true); + }else{ + data.put("isLastPage",false); + } + return data; + } + /** * 鏌ヨ鐨勮鍙� @@ -161,6 +227,25 @@ { return (startPage - 1) * pageNum; } + + public String getWhereExist() { + return whereExist; + } + + public void setWhereExist(String whereExist) { + if(StringUtils.isNull(whereExist)){ + whereExist = null; + } + this.whereExist = whereExist; + } + + public Integer getPageSize() { + return pageSize; + } + + public void setPageSize(Integer pageSize) { + this.pageSize = pageSize; + } } -- Gitblit v1.8.0