Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
SpringBlade
提交
cdd1c0f5
S
SpringBlade
项目概览
int
/
SpringBlade
12 个月 前同步成功
通知
16
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SpringBlade
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
cdd1c0f5
编写于
12月 13, 2016
作者:
Z
zhuangqian
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化分页封装方法,可自定义分页sql和countsql
上级
681a26ea
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
112 addition
and
9 deletion
+112
-9
src/main/java/com/smallchill/core/aop/AopContext.java
src/main/java/com/smallchill/core/aop/AopContext.java
+41
-1
src/main/java/com/smallchill/core/plugins/dao/Db.java
src/main/java/com/smallchill/core/plugins/dao/Db.java
+29
-0
src/main/java/com/smallchill/core/plugins/dao/DbManager.java
src/main/java/com/smallchill/core/plugins/dao/DbManager.java
+29
-1
src/main/java/com/smallchill/core/toolbox/grid/BaseGridFactory.java
...ava/com/smallchill/core/toolbox/grid/BaseGridFactory.java
+13
-7
未找到文件。
src/main/java/com/smallchill/core/aop/AopContext.java
浏览文件 @
cdd1c0f5
...
...
@@ -51,6 +51,11 @@ public class AopContext {
*/
private
String
sql
;
/**
* 从前端grid传过来的参数
*/
private
String
sqlEx
;
/**
* 追加SQL条件(程序自动生成)
*/
...
...
@@ -60,6 +65,16 @@ public class AopContext {
* 自定义SQL覆盖默认查询条件
*/
private
String
where
;
/**
* 自定义列表的sql
*/
private
String
sqlStatement
;
/**
* 自定义分页数的sql
*/
private
String
sqlCount
;
/**
* 自定义SQL参数(map形式)
...
...
@@ -113,7 +128,7 @@ public class AopContext {
public
void
setView
(
ModelAndView
view
)
{
this
.
view
=
view
;
}
public
Object
getId
()
{
return
id
;
}
...
...
@@ -138,6 +153,14 @@ public class AopContext {
this
.
sql
=
sql
;
}
public
String
getSqlEx
()
{
return
sqlEx
;
}
public
void
setSqlEx
(
String
sqlEx
)
{
this
.
sqlEx
=
sqlEx
;
}
public
String
getCondition
()
{
return
condition
;
}
...
...
@@ -154,6 +177,22 @@ public class AopContext {
this
.
where
=
where
;
}
public
String
getSqlStatement
()
{
return
sqlStatement
;
}
public
void
setSqlStatement
(
String
sqlStatement
)
{
this
.
sqlStatement
=
sqlStatement
;
}
public
String
getSqlCount
()
{
return
sqlCount
;
}
public
void
setSqlCount
(
String
sqlCount
)
{
this
.
sqlCount
=
sqlCount
;
}
public
Map
<
String
,
Object
>
getParam
()
{
return
param
;
}
...
...
@@ -170,4 +209,5 @@ public class AopContext {
this
.
tips
=
tips
;
}
}
src/main/java/com/smallchill/core/plugins/dao/Db.java
浏览文件 @
cdd1c0f5
...
...
@@ -361,6 +361,35 @@ public class Db {
return
getDbManager
().
paginate
(
sqlTemplate
,
clazz
,
paras
,
pageNum
,
pageSize
);
}
/**
* 分页
* @param sqlTemplate sql语句
* @param sqlCount count语句
* @param clazz 返回类型
* @param paras 参数
* @param pageNum 页号
* @param pageSize 数量
* @return
*/
@SuppressWarnings
(
"rawtypes"
)
public
static
BladePage
<
Map
>
paginate
(
String
sqlTemplate
,
String
sqlCount
,
Object
paras
,
int
pageNum
,
int
pageSize
){
return
getDbManager
().
paginate
(
sqlTemplate
,
sqlCount
,
paras
,
pageNum
,
pageSize
);
}
/**
* 分页
* @param sqlTemplate sql语句
* @param sqlCount count语句
* @param clazz 返回类型
* @param paras 参数
* @param pageNum 页号
* @param pageSize 数量
* @return
*/
public
static
<
T
>
BladePage
<
T
>
paginate
(
String
sqlTemplate
,
String
sqlCount
,
Class
<
T
>
clazz
,
Object
paras
,
int
pageNum
,
int
pageSize
){
return
getDbManager
().
paginate
(
sqlTemplate
,
sqlCount
,
clazz
,
paras
,
pageNum
,
pageSize
);
}
/**
* 是否存在
*
...
...
src/main/java/com/smallchill/core/plugins/dao/DbManager.java
浏览文件 @
cdd1c0f5
...
...
@@ -524,8 +524,36 @@ public class DbManager {
* @return
*/
public
<
T
>
BladePage
<
T
>
paginate
(
String
sqlTemplate
,
Class
<
T
>
clazz
,
Object
paras
,
int
pageNum
,
int
pageSize
){
return
paginate
(
sqlTemplate
,
""
,
clazz
,
paras
,
pageNum
,
pageSize
);
}
/**
* 分页
* @param sqlTemplate sql语句
* @param sqlCount count语句
* @param clazz 返回类型
* @param paras 参数
* @param pageNum 页号
* @param pageSize 数量
* @return
*/
public
<
T
>
BladePage
<
Map
>
paginate
(
String
sqlTemplate
,
String
sqlCount
,
Object
paras
,
int
pageNum
,
int
pageSize
){
return
paginate
(
sqlTemplate
,
sqlCount
,
Map
.
class
,
paras
,
pageNum
,
pageSize
);
}
/**
* 分页
* @param sqlTemplate sql语句
* @param sqlCount count语句
* @param clazz 返回类型
* @param paras 参数
* @param pageNum 页号
* @param pageSize 数量
* @return
*/
public
<
T
>
BladePage
<
T
>
paginate
(
String
sqlTemplate
,
String
sqlCount
,
Class
<
T
>
clazz
,
Object
paras
,
int
pageNum
,
int
pageSize
){
List
<
T
>
rows
=
getList
(
sqlTemplate
,
clazz
,
paras
,
pageNum
,
pageSize
);
long
count
=
queryInt
(
"SELECT COUNT(*) CNT FROM ("
+
sqlTemplate
+
") a"
,
paras
).
longValue
();
long
count
=
queryInt
(
(
StrKit
.
isBlank
(
sqlCount
)
?
"SELECT COUNT(*) CNT FROM ("
+
sqlTemplate
+
") a"
:
sqlCount
)
,
paras
).
longValue
();
BladePage
<
T
>
page
=
new
BladePage
<>(
rows
,
pageNum
,
pageSize
,
count
);
return
page
;
}
...
...
src/main/java/com/smallchill/core/toolbox/grid/BaseGridFactory.java
浏览文件 @
cdd1c0f5
...
...
@@ -72,29 +72,35 @@ public abstract class BaseGridFactory implements IGrid{
}
private
Object
paginateBySql
(
String
dbName
,
Integer
page
,
Integer
rows
,
String
sqlTemplate
,
String
para
,
String
sort
,
String
order
,
IQuery
intercept
,
BladeController
ctrl
)
{
String
statement
=
"select * from ("
+
sqlTemplate
+
") blade_statement"
;
String
sqlex
=
SqlKeyword
.
getWhere
(
para
);
Map
<
String
,
Object
>
map
=
getSqlMap
(
para
,
sort
,
order
);
String
statement
=
"select * from ("
+
sqlTemplate
+
") blade_statement"
;
String
orderBy
=
(
Func
.
isEmpty
(
map
.
get
(
Const
.
ORDER_BY_STR
)))
?
" "
:
(
" order by "
+
Func
.
toStr
(
map
.
get
(
Const
.
ORDER_BY_STR
)));
String
sqlCount
=
""
;
// 查询前拦截
AopContext
ac
=
null
;
if
(
null
!=
intercept
)
{
ac
=
new
AopContext
(
ctrl
);
ac
.
setSql
(
statement
+
sqlex
);
ac
.
setSql
(
sqlTemplate
);
ac
.
setSqlEx
(
sqlex
);
ac
.
setCondition
(
""
);
ac
.
setSqlStatement
(
""
);
ac
.
setSqlCount
(
""
);
ac
.
setParam
(
map
);
intercept
.
queryBefore
(
ac
);
statement
=
statement
+
(
StrKit
.
isBlank
(
ac
.
getWhere
())
?
(
sqlex
+
ac
.
getCondition
())
:
ac
.
getWhere
());
sqlCount
=
ac
.
getSqlCount
();
statement
=
(
StrKit
.
isBlank
(
ac
.
getSqlStatement
())
?
(
statement
+
(
StrKit
.
isBlank
(
ac
.
getWhere
())
?
(
sqlex
+
ac
.
getCondition
())
:
ac
.
getWhere
())
+
orderBy
)
:
ac
.
getSqlStatement
());
}
else
{
statement
=
statement
+
sqlex
;
statement
=
statement
+
sqlex
+
orderBy
;
}
Object
list
=
null
;
String
orderBy
=
(
Func
.
isEmpty
(
map
.
get
(
Const
.
ORDER_BY_STR
)))
?
" "
:
(
" order by "
+
Func
.
toStr
(
map
.
get
(
Const
.
ORDER_BY_STR
)));
if
(
StrKit
.
notBlank
(
dbName
)){
list
=
Db
.
init
(
dbName
).
paginate
(
statement
+
orderBy
,
Map
.
class
,
map
,
page
,
rows
);
list
=
Db
.
init
(
dbName
).
paginate
(
statement
,
sqlCount
,
map
,
page
,
rows
);
}
else
{
list
=
Db
.
paginate
(
statement
+
orderBy
,
Map
.
class
,
map
,
page
,
rows
);
list
=
Db
.
paginate
(
statement
,
sqlCount
,
map
,
page
,
rows
);
}
// 查询后拦截
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录