Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
d1f0ddb8
Commit
d1f0ddb8
authored
Jun 15, 2020
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
压缩视频
parent
3a199433
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
7 deletions
+40
-7
SqlData.java
...il-db/src/main/java/com/yanzuoguang/dao/impl/SqlData.java
+14
-0
TableStruct.java
...b/src/main/java/com/yanzuoguang/dao/impl/TableStruct.java
+26
-7
No files found.
yzg-util-db/src/main/java/com/yanzuoguang/dao/impl/SqlData.java
View file @
d1f0ddb8
...
...
@@ -160,6 +160,20 @@ public class SqlData {
return
null
;
}
/**
* 按照一种类型添加SQL语句
*
* @param clsModel 实体
* @param tag 标签
* @return
*/
public
SqlData
add
(
Class
<?>
clsModel
,
String
tag
)
{
// 生成表结构
TableStruct
table
=
new
TableStruct
(
StringHelper
.
EMPTY
,
clsModel
);
table
.
addWhereExtend
(
this
,
tag
);
return
this
;
}
/**
* 添加参数,当在SQL语句中存在参数时,用于处理。{@id} 代表前台输入参数字段为id
* 例子:
...
...
yzg-util-db/src/main/java/com/yanzuoguang/dao/impl/TableStruct.java
View file @
d1f0ddb8
...
...
@@ -536,6 +536,22 @@ public class TableStruct {
* @return 生成的语句
*/
private
void
addWhereField
(
SqlData
sql
,
String
tag
,
boolean
isRemove
)
{
addWhereBase
(
sql
,
tag
,
isRemove
);
// 查询时,不能查询到非删除的字段
addWhereRemove
(
sql
);
}
/**
* 对当前Sql语句进行扩展
*
* @param sql 需要扩展的SQL语句
* @param tag 扩展标签
*/
public
void
addWhereExtend
(
SqlData
sql
,
String
tag
)
{
addWhereBase
(
sql
,
tag
,
false
);
}
private
void
addWhereBase
(
SqlData
sql
,
String
tag
,
boolean
isRemove
)
{
addWhereFieldCommon
(
sql
,
this
.
getKey
(),
tag
);
// Where条件包含的字段
...
...
@@ -547,24 +563,27 @@ public class TableStruct {
// 非删除时需要更新的字段
fields
=
this
.
getFieldActionList
(
DaoConst
.
FIELD_COMMON
,
DaoConst
.
FIELD_REMOVE_UPDATE
);
}
// 添加普通的Where条件
for
(
TableFieldVo
field
:
fields
)
{
addWhereFieldCommon
(
sql
,
field
,
tag
);
}
// 查询时,不能查询到非删除的字段
addWhereRemove
(
sql
);
}
private
void
addWhereFieldCommon
(
SqlData
sql
,
TableFieldVo
field
,
String
tag
)
{
// 添加等于条件
sql
.
add
(
field
.
inputName
,
String
.
format
(
DaoConst
.
CODE_WHERE_EQUALS
,
tag
,
field
.
name
,
DaoConst
.
CODE_PARA
));
addWhereFieldNotExtend
(
sql
,
field
.
inputName
,
String
.
format
(
DaoConst
.
CODE_WHERE_EQUALS
,
tag
,
field
.
name
,
DaoConst
.
CODE_PARA
));
// 添加in条件
String
sqlIn
=
String
.
format
(
DaoConst
.
CODE_WHERE_IN
,
tag
,
field
.
name
,
DaoConst
.
CODE_PARA
);
if
(
field
.
inputLName
.
endsWith
(
DaoConst
.
CODE_WHERE_IN_END
))
{
sql
.
add
(
field
.
inputName
+
DaoConst
.
CODE_WHERE_IN_END_ES
,
sqlIn
);
addWhereFieldNotExtend
(
sql
,
field
.
inputName
+
DaoConst
.
CODE_WHERE_IN_END_ES
,
sqlIn
);
}
else
{
sql
.
add
(
field
.
inputName
+
DaoConst
.
CODE_WHERE_IN_END
,
sqlIn
);
addWhereFieldNotExtend
(
sql
,
field
.
inputName
+
DaoConst
.
CODE_WHERE_IN_END
,
sqlIn
);
}
}
private
void
addWhereFieldNotExtend
(
SqlData
sql
,
String
inputName
,
String
sqlWhere
)
{
if
(
sql
.
getField
(
inputName
)
==
null
)
{
// 添加等于条件
sql
.
add
(
inputName
,
sqlWhere
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment