Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
W
workflow-core
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄夏豪
workflow-core
Commits
bb9a9db9
提交
bb9a9db9
authored
3月 10, 2021
作者:
黄承天
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
api模块
修正个别错误以及读取Class部分提取为公共工具类
上级
2d7f2c96
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
66 行增加
和
50 行删除
+66
-50
ApiController.java
...a/com/tykj/workflowcore/api/controller/ApiController.java
+3
-5
ApiInfo.java
src/main/java/com/tykj/workflowcore/api/entity/ApiInfo.java
+1
-0
ApiService.java
...in/java/com/tykj/workflowcore/api/service/ApiService.java
+3
-45
ClassUtil.java
src/main/java/com/tykj/workflowcore/base/util/ClassUtil.java
+59
-0
没有找到文件。
src/main/java/com/tykj/workflowcore/api/controller/ApiController.java
浏览文件 @
bb9a9db9
...
@@ -6,15 +6,13 @@ import com.tykj.workflowcore.api.service.ApiService;
...
@@ -6,15 +6,13 @@ import com.tykj.workflowcore.api.service.ApiService;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.List
;
import
java.util.List
;
@Api
(
tags
=
"函数管理接口"
)
@Api
(
tags
=
"函数管理接口"
)
@RestController
(
"/api/info"
)
@RestController
()
@RequestMapping
(
"/api/info"
)
public
class
ApiController
{
public
class
ApiController
{
private
final
ApiService
apiService
;
private
final
ApiService
apiService
;
...
...
src/main/java/com/tykj/workflowcore/api/entity/ApiInfo.java
浏览文件 @
bb9a9db9
...
@@ -12,6 +12,7 @@ import java.util.List;
...
@@ -12,6 +12,7 @@ import java.util.List;
@AllArgsConstructor
@AllArgsConstructor
@NoArgsConstructor
@NoArgsConstructor
public
class
ApiInfo
{
public
class
ApiInfo
{
@ApiModelProperty
(
value
=
"所属类名"
)
@ApiModelProperty
(
value
=
"所属类名"
)
private
String
className
;
private
String
className
;
...
...
src/main/java/com/tykj/workflowcore/api/service/ApiService.java
浏览文件 @
bb9a9db9
...
@@ -7,8 +7,8 @@ import com.tykj.workflowcore.api.entity.ApiInfo;
...
@@ -7,8 +7,8 @@ import com.tykj.workflowcore.api.entity.ApiInfo;
import
com.tykj.workflowcore.api.entity.ClassInfo
;
import
com.tykj.workflowcore.api.entity.ClassInfo
;
import
com.tykj.workflowcore.api.entity.EntityInfo
;
import
com.tykj.workflowcore.api.entity.EntityInfo
;
import
com.tykj.workflowcore.api.entity.Parameter
;
import
com.tykj.workflowcore.api.entity.Parameter
;
import
com.tykj.workflowcore.base.util.ClassUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.io.File
;
import
java.io.File
;
...
@@ -49,7 +49,7 @@ public class ApiService {
...
@@ -49,7 +49,7 @@ public class ApiService {
private
List
<
ClassInfo
>
load
()
{
private
List
<
ClassInfo
>
load
()
{
//获取所有类
//获取所有类
List
<
Class
<?>>
classes
=
loadClassByLoader
(
getClass
().
getClassLoader
());
List
<
Class
<?>>
classes
=
ClassUtil
.
loadClassByLoader
(
getClass
().
getClassLoader
());
return
classes
.
stream
()
return
classes
.
stream
()
.
map
(
this
::
classInfo
)
.
map
(
this
::
classInfo
)
.
filter
(
Objects:
:
nonNull
)
.
filter
(
Objects:
:
nonNull
)
...
@@ -111,7 +111,7 @@ public class ApiService {
...
@@ -111,7 +111,7 @@ public class ApiService {
);
);
}
}
private
static
Boolean
isNotBasicClass
(
Class
<?>
clz
)
{
private
Boolean
isNotBasicClass
(
Class
<?>
clz
)
{
String
packagePath
=
clz
.
getPackage
().
getName
();
String
packagePath
=
clz
.
getPackage
().
getName
();
return
!
Objects
.
equals
(
packagePath
,
"java.lang"
)
return
!
Objects
.
equals
(
packagePath
,
"java.lang"
)
&&
!
Objects
.
equals
(
packagePath
,
"java.util"
);
&&
!
Objects
.
equals
(
packagePath
,
"java.util"
);
...
@@ -154,48 +154,6 @@ public class ApiService {
...
@@ -154,48 +154,6 @@ public class ApiService {
}
}
}
}
//通过loader加载所有类
private
List
<
Class
<?>>
loadClassByLoader
(
ClassLoader
load
)
{
List
<
Class
<?>>
classes
=
new
ArrayList
<>();
try
{
Enumeration
<
URL
>
urls
=
load
.
getResources
(
""
);
//放所有类型
while
(
urls
.
hasMoreElements
())
{
URL
url
=
urls
.
nextElement
();
//文件类型(其实是文件夹)
if
(
url
.
getProtocol
().
equals
(
"file"
))
{
loadClassByPath
(
null
,
url
.
getPath
(),
classes
,
load
);
}
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
classes
;
}
//通过文件路径加载所有类 root 主要用来替换path中前缀(除包路径以外的路径)
private
void
loadClassByPath
(
String
root
,
String
path
,
List
<
Class
<?>>
list
,
ClassLoader
load
)
{
File
f
=
new
File
(
path
);
if
(
root
==
null
)
root
=
f
.
getPath
();
//判断是否是class文件
if
(
f
.
isFile
()
&&
f
.
getName
().
matches
(
"^.*\\.class$"
))
{
try
{
String
classPath
=
f
.
getPath
();
//截取出className 将路径分割符替换为.(windows是\ linux、mac是/)
String
className
=
classPath
.
substring
(
root
.
length
()
+
1
,
classPath
.
length
()
-
6
).
replace
(
'/'
,
'.'
).
replace
(
'\\'
,
'.'
);
list
.
add
(
load
.
loadClass
(
className
));
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
}
}
else
{
File
[]
fs
=
f
.
listFiles
();
if
(
fs
==
null
)
return
;
for
(
File
file
:
fs
)
{
loadClassByPath
(
root
,
file
.
getPath
(),
list
,
load
);
}
}
}
/**
/**
* 把map转成指定类型的JavaBean对象
* 把map转成指定类型的JavaBean对象
*/
*/
...
...
src/main/java/com/tykj/workflowcore/base/util/ClassUtil.java
0 → 100644
浏览文件 @
bb9a9db9
package
com
.
tykj
.
workflowcore
.
base
.
util
;
import
java.io.File
;
import
java.io.IOException
;
import
java.net.URL
;
import
java.util.ArrayList
;
import
java.util.Enumeration
;
import
java.util.List
;
public
class
ClassUtil
{
/**
* 读取项目中所有Class 并以Class对象的集合返回
* @param load ClassLoader
* @return Class对象集合
*/
public
static
List
<
Class
<?>>
loadClassByLoader
(
ClassLoader
load
)
{
List
<
Class
<?>>
classes
=
new
ArrayList
<>();
try
{
Enumeration
<
URL
>
urls
=
load
.
getResources
(
""
);
//放所有类型
while
(
urls
.
hasMoreElements
())
{
URL
url
=
urls
.
nextElement
();
//文件类型(其实是文件夹)
if
(
url
.
getProtocol
().
equals
(
"file"
))
{
loadClassByPath
(
null
,
url
.
getPath
(),
classes
,
load
);
}
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
classes
;
}
//通过文件路径加载所有类 root 主要用来替换path中前缀(除包路径以外的路径)
private
static
void
loadClassByPath
(
String
root
,
String
path
,
List
<
Class
<?>>
list
,
ClassLoader
load
)
{
File
f
=
new
File
(
path
);
if
(
root
==
null
)
root
=
f
.
getPath
();
//判断是否是class文件
if
(
f
.
isFile
()
&&
f
.
getName
().
matches
(
"^.*\\.class$"
))
{
try
{
String
classPath
=
f
.
getPath
();
//截取出className 将路径分割符替换为.(windows是\ linux、mac是/)
String
className
=
classPath
.
substring
(
root
.
length
()
+
1
,
classPath
.
length
()
-
6
).
replace
(
'/'
,
'.'
).
replace
(
'\\'
,
'.'
);
list
.
add
(
load
.
loadClass
(
className
));
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
}
}
else
{
File
[]
fs
=
f
.
listFiles
();
if
(
fs
==
null
)
return
;
for
(
File
file
:
fs
)
{
loadClassByPath
(
root
,
file
.
getPath
(),
list
,
load
);
}
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论