Explorar o código

新增各种sql执行参数

周浩 %!s(int64=9) %!d(string=hai) anos
pai
achega
c0f642f3a7

+ 7 - 0
hsweb-web-bean/src/main/java/org/hsweb/web/bean/common/DeleteParam.java

@@ -0,0 +1,7 @@
+package org.hsweb.web.bean.common;
+
+/**
+ * Created by zhouhao on 16-4-19.
+ */
+public class DeleteParam extends SqlParam<DeleteParam> {
+}

+ 28 - 0
hsweb-web-bean/src/main/java/org/hsweb/web/bean/common/InsertParam.java

@@ -0,0 +1,28 @@
+package org.hsweb.web.bean.common;
+
+/**
+ * Created by zhouhao on 16-4-19.
+ */
+public class InsertParam<T> extends SqlParam<InsertParam> {
+    private T data;
+
+    public InsertParam() {
+    }
+
+    public InsertParam(T data) {
+        this.data = data;
+    }
+
+    public InsertParam<T> value(T data) {
+        this.data = data;
+        return this;
+    }
+
+    public T getData() {
+        return data;
+    }
+
+    public void setData(T data) {
+        this.data = data;
+    }
+}

+ 14 - 69
hsweb-web-bean/src/main/java/org/hsweb/web/bean/common/QueryParam.java

@@ -1,15 +1,11 @@
 package org.hsweb.web.bean.common;
 
 import java.io.Serializable;
-import java.util.*;
 
 /**
  * Created by 浩 on 2016-01-16 0016.
  */
-public class QueryParam implements Serializable {
-
-    private Map<String, Object> term = new HashMap<>();
-
+public class QueryParam extends SqlParam<QueryParam> implements Serializable {
     private static final long serialVersionUID = 7941767360194797891L;
 
     /**
@@ -37,61 +33,33 @@ public class QueryParam implements Serializable {
      */
     private String sortOrder;
 
-    /**
-     * 指定要查询的字段
-     */
-    private Set<String> includes = new LinkedHashSet<>();
 
-    /**
-     * 指定不查询的字段
-     */
-    private Set<String> excludes = new LinkedHashSet<>();
-
-    /**
-     * 指定查询的字段列表,如传入 username,name,在sql里就只会执行 select username,name from table。
-     *
-     * @param fields 查询的字段列表
-     * @return this 引用
-     */
-    public QueryParam includes(String... fields) {
-        includes.addAll(Arrays.asList(fields));
-        return this;
-    }
-
-    /**
-     * 指定不需要查询的的字段列表
-     *
-     * @param fields 不需要查询的字段列表
-     * @return this 引用
-     */
-    public QueryParam excludes(String... fields) {
-        excludes.addAll(Arrays.asList(fields));
-        includes.removeAll(Arrays.asList(fields));
-        return this;
-    }
-
-    public QueryParam where(String key, Object value) {
-        this.term.put(key, value);
+    public QueryParam orderBy(String sortField) {
+        orderBy(sortField, true);
         return this;
     }
 
-    public QueryParam where(Map<String, Object> conditions) {
-        this.term.putAll(conditions);
+    public QueryParam orderBy(String sortField, boolean asc) {
+        setSortField(sortField);
+        setSortOrder(asc ? "asc" : "desc");
         return this;
     }
 
-    public QueryParam orderBy(String sortField) {
-        orderBy(sortField, true);
+    public QueryParam doPaging(int pageIndex) {
+        this.pageIndex = pageIndex;
+        this.paging = true;
         return this;
     }
 
-    public QueryParam orderBy(String sortField, boolean asc) {
-        setSortField(sortField);
-        setSortOrder(asc ? "asc" : "desc");
+    public QueryParam doPaging(int pageIndex, int pageSize) {
+        this.pageIndex = pageIndex;
+        this.pageSize = pageSize;
+        this.paging = true;
         return this;
     }
 
     public QueryParam rePaging(int total) {
+        paging = true;
         // 当前页没有数据后跳转到最后一页
         if (this.getPageIndex() != 0 && (pageIndex * pageSize) >= total) {
             int tmp = total / this.getPageSize();
@@ -142,27 +110,4 @@ public class QueryParam implements Serializable {
         this.sortOrder = sortOrder;
     }
 
-    public Set<String> getIncludes() {
-        return includes;
-    }
-
-    public void setIncludes(Set<String> includes) {
-        this.includes = includes;
-    }
-
-    public Set<String> getExcludes() {
-        return excludes;
-    }
-
-    public void setExcludes(Set<String> excludes) {
-        this.excludes = excludes;
-    }
-
-    public Map<String, Object> getTerm() {
-        return term;
-    }
-
-    public void setTerm(Map<String, Object> term) {
-        this.term = term;
-    }
 }

+ 68 - 0
hsweb-web-bean/src/main/java/org/hsweb/web/bean/common/SqlParam.java

@@ -0,0 +1,68 @@
+package org.hsweb.web.bean.common;
+
+import java.util.*;
+
+/**
+ * Created by zhouhao on 16-4-19.
+ */
+public class SqlParam<R extends SqlParam> {
+    /**
+     * 执行条件
+     */
+    protected Map<String, Object> term = new HashMap<>();
+
+    /**
+     * 指定要处理的字段
+     */
+    protected Set<String> includes = new LinkedHashSet<>();
+
+    /**
+     * 指定不处理的字段
+     */
+    protected Set<String> excludes = new LinkedHashSet<>();
+
+    public R includes(String... fields) {
+        includes.addAll(Arrays.asList(fields));
+        return (R) this;
+    }
+
+    public R excludes(String... fields) {
+        excludes.addAll(Arrays.asList(fields));
+        includes.removeAll(Arrays.asList(fields));
+        return (R) this;
+    }
+
+    public R where(String key, Object value) {
+        this.term.put(key, value);
+        return (R) this;
+    }
+
+    public R where(Map<String, Object> conditions) {
+        this.term.putAll(conditions);
+        return (R) this;
+    }
+
+    public Map<String, Object> getTerm() {
+        return term;
+    }
+
+    public Set<String> getIncludes() {
+        return includes;
+    }
+
+    public Set<String> getExcludes() {
+        return excludes;
+    }
+
+    public void setIncludes(Set<String> includes) {
+        this.includes = includes;
+    }
+
+    public void setExcludes(Set<String> excludes) {
+        this.excludes = excludes;
+    }
+
+    public void setTerm(Map<String, Object> term) {
+        this.term = term;
+    }
+}

+ 28 - 0
hsweb-web-bean/src/main/java/org/hsweb/web/bean/common/UpdateParam.java

@@ -0,0 +1,28 @@
+package org.hsweb.web.bean.common;
+
+/**
+ * Created by zhouhao on 16-4-19.
+ */
+public class UpdateParam<T> extends SqlParam<UpdateParam> {
+    private T data;
+
+    public UpdateParam() {
+    }
+
+    public UpdateParam(T data) {
+        this.data = data;
+    }
+
+    public UpdateParam<T> set(T data) {
+        this.data = data;
+        return this;
+    }
+
+    public T getData() {
+        return data;
+    }
+
+    public void setData(T data) {
+        this.data = data;
+    }
+}