提交 | 用户 | age
|
5c5945
|
1 |
package com.hx.mybatisTool; |
E |
2 |
|
|
3 |
import com.hx.exception.TipsException; |
|
4 |
import com.hx.util.StringUtils; |
|
5 |
|
|
6 |
import java.util.Map; |
|
7 |
|
|
8 |
/** |
|
9 |
* mybatis 自定义处理sql语句 |
|
10 |
* @author chenjiahe |
|
11 |
* @Data: 2020-06-08 |
|
12 |
*/ |
|
13 |
public class SqlSentence { |
|
14 |
|
|
15 |
private String sqlSentence; |
|
16 |
|
|
17 |
private Map<String,Object> m; |
|
18 |
/**排序*/ |
|
19 |
private String orderBy; |
|
20 |
/**开始页数*/ |
|
21 |
private Integer startPage = 0; |
|
22 |
/**每页数量*/ |
|
23 |
private Integer pageNum = 0; |
|
24 |
|
|
25 |
////////////////////////////////////////////////////////////// |
|
26 |
|
|
27 |
/********************mother****************************/ |
|
28 |
|
|
29 |
public SqlSentence() |
|
30 |
{ |
|
31 |
|
|
32 |
} |
|
33 |
|
|
34 |
public SqlSentence(Class c, String where, Map<String, Object> values) |
|
35 |
{ |
|
36 |
if(StringUtils.isEmpty(where)) |
|
37 |
{ |
|
38 |
throw new TipsException("sql is null"); |
|
39 |
} |
|
40 |
|
|
41 |
if(values == null) |
|
42 |
{ |
|
43 |
throw new TipsException("values is null"); |
|
44 |
} |
|
45 |
|
|
46 |
sqlSentence = "select * from " + c.getSimpleName()+ " where " + where; |
|
47 |
m = values; |
|
48 |
} |
|
49 |
|
|
50 |
public SqlSentence(String where, Map<String, Object> values) |
|
51 |
{ |
|
52 |
if(StringUtils.isEmpty(where)) |
|
53 |
{ |
|
54 |
throw new TipsException("sql is null"); |
|
55 |
} |
|
56 |
|
|
57 |
if(values == null) |
|
58 |
{ |
|
59 |
throw new TipsException("values is null"); |
|
60 |
} |
|
61 |
|
|
62 |
sqlSentence = where; |
|
63 |
m = values; |
|
64 |
} |
|
65 |
|
|
66 |
|
|
67 |
/** |
|
68 |
* sql整条语句 |
|
69 |
* @param sql 如:select * from user Where name = #{m.userName} order by age desc |
|
70 |
* @param values 存放的值如:values.put("userName","ChenJiaHe") |
|
71 |
*/ |
|
72 |
public void sqlSentence(String sql,Map<String,Object> values) { |
|
73 |
if(StringUtils.isEmpty(sql)) |
|
74 |
{ |
|
75 |
throw new TipsException("sql is null"); |
|
76 |
} |
|
77 |
|
|
78 |
if(values == null) |
|
79 |
{ |
|
80 |
throw new TipsException("values is null"); |
|
81 |
} |
|
82 |
|
|
83 |
sqlSentence = sql; |
|
84 |
m = values; |
|
85 |
} |
|
86 |
|
|
87 |
|
|
88 |
/************************************************************************/ |
|
89 |
|
|
90 |
public Map<String, Object> getM() { |
|
91 |
return m; |
|
92 |
} |
|
93 |
|
|
94 |
public void setM(Map<String, Object> m) { |
|
95 |
this.m = m; |
|
96 |
} |
|
97 |
|
|
98 |
public String getSqlSentence() { |
|
99 |
return sqlSentence; |
|
100 |
} |
|
101 |
|
|
102 |
public void setSqlSentence(String sqlSentence) { |
|
103 |
this.sqlSentence = sqlSentence; |
|
104 |
} |
|
105 |
|
|
106 |
public String getOrderBy() { |
|
107 |
return orderBy; |
|
108 |
} |
|
109 |
|
|
110 |
public void setOrderBy(String orderBy) { |
|
111 |
this.orderBy = orderBy; |
|
112 |
} |
|
113 |
|
|
114 |
public Integer getStartPage() { |
|
115 |
return startPage; |
|
116 |
} |
|
117 |
|
|
118 |
public void setStartPage(Integer startPage) { |
|
119 |
this.startPage = startPage; |
|
120 |
} |
|
121 |
|
|
122 |
public Integer getPageNum() { |
|
123 |
return pageNum; |
|
124 |
} |
|
125 |
|
|
126 |
public void setPageNum(Integer pageNum) { |
|
127 |
this.pageNum = pageNum; |
|
128 |
} |
|
129 |
|
|
130 |
public Integer getStartIndex() |
|
131 |
{ |
|
132 |
return (startPage - 1) * pageNum; |
|
133 |
} |
|
134 |
|
|
135 |
} |
|
136 |
|
|
137 |
|