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
7e71f5a5
Commit
7e71f5a5
authored
Nov 27, 2019
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
接口文档的支持
parent
1c8c8da5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
78 additions
and
11 deletions
+78
-11
BaseDaoImpl.java
...b/src/main/java/com/yanzuoguang/dao/impl/BaseDaoImpl.java
+78
-11
No files found.
yzg-util-db/src/main/java/com/yanzuoguang/dao/impl/BaseDaoImpl.java
View file @
7e71f5a5
...
...
@@ -8,7 +8,6 @@ import com.yanzuoguang.util.helper.DateHelper;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.vo.*
;
import
java.lang.reflect.Array
;
import
java.util.*
;
/**
...
...
@@ -338,15 +337,12 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
}
/**
*
加载数据
*
获取请求对象爱
*
* @param model 加载数据的请求参数
* @param resultClass 需要加载的数据的类型
* @param <T> 返回数据的类型
* @return 需要返回的数据
* @param model 来源对象
* @return
*/
@Override
public
<
T
extends
Object
>
T
load
(
Object
model
,
Class
<
T
>
resultClass
)
{
protected
Object
getLoadFrom
(
Object
model
)
{
// 获取来源主键
Object
from
=
model
;
String
key
=
this
.
getInputKey
(
from
);
...
...
@@ -357,6 +353,22 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
this
.
setKeyString
(
from
,
key
);
}
return
from
;
}
/**
* 加载数据
*
* @param model 加载数据的请求参数
* @param resultClass 需要加载的数据的类型
* @param <T> 返回数据的类型
* @return 需要返回的数据
*/
@Override
public
<
T
extends
Object
>
T
load
(
Object
model
,
Class
<
T
>
resultClass
)
{
// 获取来源主键
String
key
=
this
.
getInputKey
(
model
);
Object
from
=
this
.
getLoadFrom
(
model
);
// 通过传入数据进行加载
T
to
=
this
.
queryFirst
(
resultClass
,
DaoConst
.
LOAD
,
from
);
if
(
to
==
null
)
{
...
...
@@ -586,15 +598,58 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
return
this
.
updateSql
(
sqlName
+
"_GroupAdd"
,
model
);
}
/***
* 查询数据是否存在,当存在时修改,否则增加
* @param cls 需要创建的实体的类型
* @param requests 前台参数,不能包含主键以及其他不需要修改的字段
* @return 保存成功,返回保存的ID,保存失败,返回空值
*/
public
<
T
extends
Object
>
List
<
String
>
saveByLoadArray
(
Class
<
T
>
cls
,
Object
...
requests
)
{
return
this
.
saveByLoadList
(
cls
,
Arrays
.
asList
(
requests
));
}
/***
* 查询数据是否存在,当存在时修改,否则增加
* @param cls 需要创建的实体的类型
* @param requests 前台参数,不能包含主键以及其他不需要修改的字段
* @return 保存成功,返回保存的ID,保存失败,返回空值
*/
public
<
T
extends
Object
>
List
<
String
>
saveByLoadList
(
Class
<
T
>
cls
,
List
<
Object
>
requests
)
{
List
<
String
>
ret
=
new
ArrayList
<>();
if
(
requests
!=
null
)
{
for
(
Object
model
:
requests
)
{
ret
.
add
(
this
.
saveByLoad
(
cls
,
model
));
}
}
return
ret
;
}
/***
* 查询数据是否存在,当存在时修改,否则增加
* @param cls 需要创建的实体的类型
* @param sqlName 执行的SQL语句
* @param request 前台参数,不能包含主键以及其他不需要修改的字段
* @return 保存成功,返回保存的ID,保存失败,返回空值
*/
public
<
T
extends
Object
>
String
saveWith
(
Class
<
T
>
cls
,
String
sqlName
,
Object
request
)
{
T
from
=
this
.
queryFirst
(
cls
,
sqlName
,
request
);
public
<
T
extends
Object
>
String
saveByLoad
(
Class
<
T
>
cls
,
Object
request
)
{
String
key
=
this
.
getInputKey
(
request
);
T
from
=
null
;
if
(!
StringHelper
.
isEmpty
(
key
))
{
from
=
this
.
load
(
request
,
cls
);
}
return
saveFromCreate
(
cls
,
from
,
request
);
}
/**
* 根据from来创建对象,对象存在时修改,对象不存在时创建
*
* @param cls 自动创建的对象类型
* @param from 需要修改的对象,当该对象不存在时创建数据
* @param request 需要创建的对象
* @param <T> 创建的数据类型
* @return 创建成功的编号
*/
protected
<
T
extends
Object
>
String
saveFromCreate
(
Class
<
T
>
cls
,
T
from
,
Object
request
)
{
if
(
from
==
null
)
{
try
{
from
=
cls
.
newInstance
();
...
...
@@ -609,6 +664,18 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
}
}
/***
* 查询数据是否存在,当存在时修改,否则增加
* @param cls 需要创建的实体的类型
* @param sqlName 执行的SQL语句
* @param request 前台参数,不能包含主键以及其他不需要修改的字段
* @return 保存成功,返回保存的ID,保存失败,返回空值
*/
public
<
T
extends
Object
>
String
saveWith
(
Class
<
T
>
cls
,
String
sqlName
,
Object
request
)
{
T
from
=
this
.
queryFirst
(
cls
,
sqlName
,
request
);
return
saveFromCreate
(
cls
,
from
,
request
);
}
/**
* 创建成功后的处理
*
...
...
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