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
0815dfd7
Commit
0815dfd7
authored
Apr 04, 2019
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
实体生成
parent
827f4987
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
98 additions
and
11 deletions
+98
-11
StringHelper.java
...c/main/java/com/yanzuoguang/util/helper/StringHelper.java
+41
-0
DaoConst.java
yzg-util-db/src/main/java/com/yanzuoguang/dao/DaoConst.java
+9
-0
AllBeanRowMapper.java
...c/main/java/com/yanzuoguang/db/Impl/AllBeanRowMapper.java
+35
-5
ConfigDb.java
...til-db/src/main/java/com/yanzuoguang/extend/ConfigDb.java
+13
-6
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/StringHelper.java
View file @
0815dfd7
...
...
@@ -840,4 +840,45 @@ public class StringHelper {
return
sb
.
toString
();
}
/**
* 获取CamelCase命名,去掉下划线
*
* @param from 原名称
* @return 修改后的名称
*/
public
static
String
getCamelCase
(
String
from
)
{
StringBuilder
result
=
new
StringBuilder
();
String
a
[]
=
from
.
split
(
"_"
);
for
(
String
s
:
a
)
{
if
(
result
.
length
()
==
0
)
{
result
.
append
(
s
.
substring
(
0
,
1
).
toLowerCase
());
result
.
append
(
s
.
substring
(
1
));
}
else
{
result
.
append
(
s
.
substring
(
0
,
1
).
toUpperCase
());
result
.
append
(
s
.
substring
(
1
));
}
}
return
result
.
toString
();
}
/***
* 驼峰命名转为下划线命名大写
*
* @param from
* 驼峰命名的字符串
*/
public
static
String
getUnderLine
(
String
from
)
{
if
(
from
.
contains
(
"_"
))
{
return
from
;
}
StringBuilder
sb
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
from
.
length
();
i
++)
{
char
c
=
from
.
charAt
(
i
);
if
(
Character
.
isUpperCase
(
c
))
{
sb
.
append
(
"_"
);
}
sb
.
append
(
c
);
}
return
sb
.
toString
().
toUpperCase
();
}
}
yzg-util-db/src/main/java/com/yanzuoguang/dao/DaoConst.java
View file @
0815dfd7
...
...
@@ -39,4 +39,13 @@ public class DaoConst {
* GROUP查询数据的SQL语句
*/
public
static
final
String
GroupQuery
=
"GroupQuery"
;
/**
* 驼峰式命名
*/
public
static
final
int
RowNameTypeCamelCase
=
0
;
/**
* 原字段
*/
public
static
final
int
RowNameTypeNoChange
=
1
;
}
yzg-util-db/src/main/java/com/yanzuoguang/db/Impl/AllBeanRowMapper.java
View file @
0815dfd7
package
com
.
yanzuoguang
.
db
.
Impl
;
import
com.yanzuoguang.dao.DaoConst
;
import
com.yanzuoguang.extend.ConfigDb
;
import
com.yanzuoguang.util.base.ObjectHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.log.Log
;
import
com.yanzuoguang.util.vo.MapRow
;
import
org.springframework.beans.*
;
...
...
@@ -110,7 +112,17 @@ public class AllBeanRowMapper<T> implements RowMapper<T> {
* @param name the string containing original name
* @return the converted name
*/
public
static
String
underscoreName
(
String
name
)
{
public
String
underscoreName
(
String
name
)
{
return
underscoreNameBase
(
name
);
}
/**
* 获取列明
*
* @param name
* @return
*/
private
static
String
underscoreNameBase
(
String
name
)
{
if
(!
StringUtils
.
hasLength
(
name
))
{
return
""
;
}
...
...
@@ -126,7 +138,7 @@ public class AllBeanRowMapper<T> implements RowMapper<T> {
public
static
MapRow
toLoweRow
(
MapRow
from
)
{
MapRow
to
=
new
MapRow
();
for
(
String
key
:
from
.
keySet
())
{
to
.
put
(
underscoreName
(
key
),
from
.
get
(
key
));
to
.
put
(
underscoreName
Base
(
key
),
from
.
get
(
key
));
}
return
to
;
}
...
...
@@ -138,9 +150,9 @@ public class AllBeanRowMapper<T> implements RowMapper<T> {
* @return
*/
public
static
Object
getLoweRowField
(
MapRow
from
,
String
field
)
{
field
=
underscoreName
(
field
);
field
=
underscoreName
Base
(
field
);
for
(
String
key
:
from
.
keySet
())
{
if
(
underscoreName
(
key
).
equals
(
field
))
{
if
(
underscoreName
Base
(
key
).
equals
(
field
))
{
return
from
.
get
(
key
);
}
}
...
...
@@ -167,7 +179,7 @@ public class AllBeanRowMapper<T> implements RowMapper<T> {
String
underscoredName
=
underscoreName
(
column
);
if
(
this
.
isMapping
)
{
Object
value
=
JdbcUtils
.
getResultSetValue
(
rs
,
index
);
((
Map
)
mappedObject
).
put
(
column
,
value
);
((
Map
)
mappedObject
).
put
(
getCamelCase
(
column
)
,
value
);
}
else
if
(!
this
.
mappedIsFields
.
containsKey
(
underscoredName
))
{
continue
;
}
else
if
(!
this
.
mappedIsFields
.
get
(
underscoredName
))
{
...
...
@@ -224,6 +236,24 @@ public class AllBeanRowMapper<T> implements RowMapper<T> {
return
mappedObject
;
}
/**
* 设置SameCase命名方式
*
* @param column
* @return
*/
private
String
getCamelCase
(
String
column
)
{
switch
(
configDb
.
getRowNameType
())
{
case
DaoConst
.
RowNameTypeNoChange
:
break
;
case
DaoConst
.
RowNameTypeCamelCase
:
default
:
column
=
StringHelper
.
getCamelCase
(
column
);
break
;
}
return
column
;
}
/**
* Initialize the given BeanWrapper to be used for row mapping.
* To be called for each row.
...
...
yzg-util-db/src/main/java/com/yanzuoguang/extend/ConfigDb.java
View file @
0815dfd7
...
...
@@ -12,28 +12,35 @@ public class ConfigDb {
* 打印映射日志
*/
@Value
(
"${yzg.PrintMapper:true}"
)
private
boolean
P
rintMapper
;
private
boolean
p
rintMapper
;
/**
* 打印SQL日志
*/
@Value
(
"${yzg.PrintSql:true}"
)
private
boolean
P
rintSql
;
private
boolean
p
rintSql
;
/**
* 判断是否匹配过滤
*/
@Value
(
"${yzg.PrintSqlFilter:}"
)
private
String
PrintSqlFilter
;
private
String
printSqlFilter
;
@Value
(
"${yzg.row.name.type:0}"
)
private
int
rowNameType
;
public
boolean
isPrintMapper
()
{
return
P
rintMapper
;
return
p
rintMapper
;
}
public
boolean
isPrintSql
()
{
return
P
rintSql
;
return
p
rintSql
;
}
public
String
getPrintSqlFilter
()
{
return
PrintSqlFilter
;
return
printSqlFilter
;
}
public
int
getRowNameType
()
{
return
rowNameType
;
}
}
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