Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
D
dataWareHose
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄夏豪
dataWareHose
Commits
f2ecf57a
提交
f2ecf57a
authored
7月 19, 2021
作者:
hjf
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
添加了lib
上级
c5719fd5
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
155 行增加
和
0 行删除
+155
-0
pom.xml
pom.xml
+7
-0
YmlUtils.java
src/main/java/com/tykj/base/util/YmlUtils.java
+148
-0
generateAnnotation-1.0-SNAPSHOT.jar
...va/com/tykj/model/lib/generateAnnotation-1.0-SNAPSHOT.jar
+0
-0
没有找到文件。
pom.xml
浏览文件 @
f2ecf57a
...
@@ -94,6 +94,13 @@
...
@@ -94,6 +94,13 @@
<artifactId>
jpa-spec
</artifactId>
<artifactId>
jpa-spec
</artifactId>
<version>
3.1.1
</version>
<version>
3.1.1
</version>
</dependency>
</dependency>
<dependency>
<groupId>
com.sun
</groupId>
<artifactId>
tools
</artifactId>
<version>
1.8
</version>
<scope>
system
</scope>
<systemPath>
${java.home}/../lib/tools.jar
</systemPath>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
...
...
src/main/java/com/tykj/base/util/YmlUtils.java
0 → 100644
浏览文件 @
f2ecf57a
package
com
.
tykj
.
base
.
util
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.util.ResourceUtils
;
import
org.yaml.snakeyaml.Yaml
;
import
java.io.*
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Set
;
/**
* @author hunmeng
* @create 2020-01-10 20:34
*/
public
class
YmlUtils
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
YmlUtils
.
class
);
private
static
String
bootstrap_file
=
"classpath:application.yml"
;
private
static
Map
<
String
,
String
>
result
=
new
HashMap
<>();
/**
* 根据文件名获取yml的文件内容
* @param filePath
* @param keys 第一个参数对应第一个key,第二个参数对应第二个key 比如spring.name下的所有 就是两个参数、
* getYmlByFileName(bootstrap_file,"spring", "name");
* @return
*/
public
static
Map
<
String
,
String
>
getYmlByFileName
(
String
filePath
,
String
...
keys
)
{
result
=
new
HashMap
<>();
if
(
filePath
==
null
)
filePath
=
bootstrap_file
;
InputStream
in
=
null
;
try
{
File
file
=
ResourceUtils
.
getFile
(
filePath
);
in
=
new
BufferedInputStream
(
new
FileInputStream
(
file
));
Yaml
props
=
new
Yaml
();
Object
obj
=
props
.
loadAs
(
in
,
Map
.
class
);
Map
<
String
,
Object
>
param
=
(
Map
<
String
,
Object
>)
obj
;
for
(
Map
.
Entry
<
String
,
Object
>
entry:
param
.
entrySet
()){
String
key
=
entry
.
getKey
();
Object
val
=
entry
.
getValue
();
if
(
keys
.
length
!=
0
&&
!
keys
[
0
].
equals
(
key
)){
continue
;
}
if
(
val
instanceof
Map
){
forEachYaml
(
key
,(
Map
<
String
,
Object
>)
val
,
1
,
keys
);
}
else
{
result
.
put
(
key
,
val
.
toString
());
}
}
return
result
;
}
catch
(
FileNotFoundException
e
)
{
LOGGER
.
error
(
e
.
getMessage
(),
e
);
}
finally
{
if
(
in
!=
null
){
try
{
in
.
close
();
}
catch
(
IOException
e
)
{
LOGGER
.
error
(
e
.
getMessage
(),
e
);
}
}
}
return
null
;
}
/**
* 根据key获取值
* @param key
* @return
*/
public
static
String
getValue
(
String
key
)
throws
FileNotFoundException
{
Map
<
String
,
String
>
map
=
getYmlByFileName
(
null
);
if
(
map
==
null
)
return
null
;
return
map
.
get
(
key
);
}
/**
* 遍历yml文件,获取map集合
* @param key_str
* @param obj
* @param i
* @param keys
* @return
*/
public
static
Map
<
String
,
String
>
forEachYaml
(
String
key_str
,
Map
<
String
,
Object
>
obj
,
int
i
,
String
...
keys
){
for
(
Map
.
Entry
<
String
,
Object
>
entry:
obj
.
entrySet
()){
String
key
=
entry
.
getKey
();
Object
val
=
entry
.
getValue
();
if
(
keys
.
length
>
i
&&
!
keys
[
i
].
equals
(
key
)){
continue
;
}
String
str_new
=
""
;
if
(
StringUtils
.
isNotEmpty
(
key_str
)){
str_new
=
key_str
+
"."
+
key
;
}
else
{
str_new
=
key
;
}
if
(
val
instanceof
Map
){
forEachYaml
(
str_new
,(
Map
<
String
,
Object
>)
val
,
++
i
,
keys
);
i
--;
}
else
{
result
.
put
(
str_new
,
val
.
toString
());
}
}
return
result
;
}
/**
* 获取bootstrap.yml的name
* @return
*/
public
static
String
getApplicationName
()
throws
FileNotFoundException
{
return
getYmlByFileName
(
bootstrap_file
).
get
(
"server.port"
);
}
/**
* 获取bootstrap.yml的name
* @return
*/
public
static
String
getApplicationName1
()
throws
FileNotFoundException
{
String
name
=
getYmlByFileName
(
bootstrap_file
).
get
(
"spring.application.name"
);
return
name
+
"center"
;
}
public
static
void
main
(
String
[]
args
)
throws
FileNotFoundException
{
Map
<
String
,
String
>
ymlByFileName
=
getYmlByFileName
(
bootstrap_file
,
"spring"
);
Set
<
Map
.
Entry
<
String
,
String
>>
entries
=
ymlByFileName
.
entrySet
();
for
(
Map
.
Entry
<
String
,
String
>
entry
:
entries
)
{
if
(
entry
.
getKey
().
equals
(
"spring.datasource.driver-class-name"
)){
if
(
entry
.
getValue
().
contains
(
"com.mysql.cj.jdbc.Driver"
)||
entry
.
getValue
().
contains
(
"com.mysql.jdbc.Driver"
)){
System
.
out
.
println
(
111
);
}
}
}
}
}
src/main/java/com/tykj/model/lib/generateAnnotation-1.0-SNAPSHOT.jar
0 → 100644
浏览文件 @
f2ecf57a
File added
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论