Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
yubinCloud
fairy-wiki
提交
614ae713
F
fairy-wiki
项目概览
yubinCloud
/
fairy-wiki
通知
4
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
fairy-wiki
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
614ae713
编写于
4月 21, 2021
作者:
yubinCloud
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
7-3 使分类管理不再显示分页
上级
1da34f09
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
132 addition
and
158 deletion
+132
-158
src/main/java/io/github/yubincloud/fairywiki/aspect/LogAspect.java
...java/io/github/yubincloud/fairywiki/aspect/LogAspect.java
+101
-101
src/main/java/io/github/yubincloud/fairywiki/controller/CategoryController.java
...b/yubincloud/fairywiki/controller/CategoryController.java
+10
-0
src/main/java/io/github/yubincloud/fairywiki/service/CategoryService.java
.../github/yubincloud/fairywiki/service/CategoryService.java
+10
-0
web/src/views/admin/admin-category.vue
web/src/views/admin/admin-category.vue
+11
-57
未找到文件。
src/main/java/io/github/yubincloud/fairywiki/aspect/LogAspect.java
浏览文件 @
614ae713
//
package io.github.yubincloud.fairywiki.aspect;
//
//
import com.alibaba.fastjson.JSONObject;
//
import com.alibaba.fastjson.support.spring.PropertyPreFilters;
//
import org.aspectj.lang.JoinPoint;
//
import org.aspectj.lang.ProceedingJoinPoint;
//
import org.aspectj.lang.Signature;
//
import org.aspectj.lang.annotation.Around;
//
import org.aspectj.lang.annotation.Aspect;
//
import org.aspectj.lang.annotation.Before;
//
import org.aspectj.lang.annotation.Pointcut;
//
import org.slf4j.Logger;
//
import org.slf4j.LoggerFactory;
//
import org.springframework.stereotype.Component;
//
import org.springframework.web.context.request.RequestContextHolder;
//
import org.springframework.web.context.request.ServletRequestAttributes;
//
import org.springframework.web.multipart.MultipartFile;
//
//
import javax.servlet.ServletRequest;
//
import javax.servlet.ServletResponse;
//
import javax.servlet.http.HttpServletRequest;
//
//
@Aspect
//
@Component
//
public class LogAspect {
//
//
private final static Logger LOG = LoggerFactory.getLogger(LogAspect.class);
//
//
/** 定义一个切点 */
//
@Pointcut("execution(public * io.github.yubincloud.fairywiki.controller..*Controller.*(..))")
//
public void controllerPointcut() {}
//
//
//
@Before("controllerPointcut()")
//
public void doBefore(JoinPoint joinPoint) {
//
//
// 开始打印请求日志
//
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//
HttpServletRequest request = attributes.getRequest();
//
Signature signature = joinPoint.getSignature();
//
String name = signature.getName();
//
//
// 打印请求信息
//
LOG.info("------------- 开始 -------------");
//
LOG.info("请求地址: {} {}", request.getRequestURL().toString(), request.getMethod());
//
LOG.info("类名方法: {}.{}", signature.getDeclaringTypeName(), name);
//
LOG.info("远程地址: {}", request.getRemoteAddr());
//
//
// 打印请求参数
//
Object[] args = joinPoint.getArgs();
//
// LOG.info("请求参数: {}", JSONObject.toJSONString(args));
//
//
Object[] arguments = new Object[args.length];
//
for (int i = 0; i < args.length; i++) {
//
if (args[i] instanceof ServletRequest
//
|| args[i] instanceof ServletResponse
//
|| args[i] instanceof MultipartFile) {
//
continue;
//
}
//
arguments[i] = args[i];
//
}
//
// 排除字段,敏感字段或太长的字段不显示
//
String[] excludeProperties = {"password", "file"};
//
PropertyPreFilters filters = new PropertyPreFilters();
//
PropertyPreFilters.MySimplePropertyPreFilter excludefilter = filters.addFilter();
//
excludefilter.addExcludes(excludeProperties);
//
LOG.info("请求参数: {}", JSONObject.toJSONString(arguments, excludefilter));
//
}
//
//
@Around("controllerPointcut()")
//
public Object doAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
//
long startTime = System.currentTimeMillis();
//
Object result = proceedingJoinPoint.proceed();
//
// 排除字段,敏感字段或太长的字段不显示
//
String[] excludeProperties = {"password", "file"};
//
PropertyPreFilters filters = new PropertyPreFilters();
//
PropertyPreFilters.MySimplePropertyPreFilter excludefilter = filters.addFilter();
//
excludefilter.addExcludes(excludeProperties);
//
LOG.info("返回结果: {}", JSONObject.toJSONString(result, excludefilter));
//
LOG.info("------------- 结束 耗时:{} ms -------------", System.currentTimeMillis() - startTime);
//
return result;
//
}
//
//
/**
//
* 使用nginx做反向代理,需要用该方法才能取到真实的远程IP
//
*/
//
public String getRemoteIp(HttpServletRequest request) {
//
String ip = request.getHeader("x-forwarded-for");
//
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
//
ip = request.getHeader("Proxy-Client-IP");
//
}
//
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
//
ip = request.getHeader("WL-Proxy-Client-IP");
//
}
//
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
//
ip = request.getRemoteAddr();
//
}
//
return ip;
//
}
//
//
}
package
io.github.yubincloud.fairywiki.aspect
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.support.spring.PropertyPreFilters
;
import
org.aspectj.lang.JoinPoint
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.Signature
;
import
org.aspectj.lang.annotation.Around
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Before
;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.servlet.ServletRequest
;
import
javax.servlet.ServletResponse
;
import
javax.servlet.http.HttpServletRequest
;
@Aspect
@Component
public
class
LogAspect
{
private
final
static
Logger
LOG
=
LoggerFactory
.
getLogger
(
LogAspect
.
class
);
/** 定义一个切点 */
@Pointcut
(
"execution(public * io.github.yubincloud.fairywiki.controller..*Controller.*(..))"
)
public
void
controllerPointcut
()
{}
@Before
(
"controllerPointcut()"
)
public
void
doBefore
(
JoinPoint
joinPoint
)
{
// 开始打印请求日志
ServletRequestAttributes
attributes
=
(
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
();
HttpServletRequest
request
=
attributes
.
getRequest
();
Signature
signature
=
joinPoint
.
getSignature
();
String
name
=
signature
.
getName
();
// 打印请求信息
LOG
.
info
(
"------------- 开始 -------------"
);
LOG
.
info
(
"请求地址: {} {}"
,
request
.
getRequestURL
().
toString
(),
request
.
getMethod
());
LOG
.
info
(
"类名方法: {}.{}"
,
signature
.
getDeclaringTypeName
(),
name
);
LOG
.
info
(
"远程地址: {}"
,
request
.
getRemoteAddr
());
// 打印请求参数
Object
[]
args
=
joinPoint
.
getArgs
();
// LOG.info("请求参数: {}", JSONObject.toJSONString(args));
Object
[]
arguments
=
new
Object
[
args
.
length
];
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
if
(
args
[
i
]
instanceof
ServletRequest
||
args
[
i
]
instanceof
ServletResponse
||
args
[
i
]
instanceof
MultipartFile
)
{
continue
;
}
arguments
[
i
]
=
args
[
i
];
}
// 排除字段,敏感字段或太长的字段不显示
String
[]
excludeProperties
=
{
"password"
,
"file"
};
PropertyPreFilters
filters
=
new
PropertyPreFilters
();
PropertyPreFilters
.
MySimplePropertyPreFilter
excludefilter
=
filters
.
addFilter
();
excludefilter
.
addExcludes
(
excludeProperties
);
LOG
.
info
(
"请求参数: {}"
,
JSONObject
.
toJSONString
(
arguments
,
excludefilter
));
}
@Around
(
"controllerPointcut()"
)
public
Object
doAround
(
ProceedingJoinPoint
proceedingJoinPoint
)
throws
Throwable
{
long
startTime
=
System
.
currentTimeMillis
();
Object
result
=
proceedingJoinPoint
.
proceed
();
// 排除字段,敏感字段或太长的字段不显示
String
[]
excludeProperties
=
{
"password"
,
"file"
};
PropertyPreFilters
filters
=
new
PropertyPreFilters
();
PropertyPreFilters
.
MySimplePropertyPreFilter
excludefilter
=
filters
.
addFilter
();
excludefilter
.
addExcludes
(
excludeProperties
);
LOG
.
info
(
"返回结果: {}"
,
JSONObject
.
toJSONString
(
result
,
excludefilter
));
LOG
.
info
(
"------------- 结束 耗时:{} ms -------------"
,
System
.
currentTimeMillis
()
-
startTime
);
return
result
;
}
/**
* 使用nginx做反向代理,需要用该方法才能取到真实的远程IP
*/
public
String
getRemoteIp
(
HttpServletRequest
request
)
{
String
ip
=
request
.
getHeader
(
"x-forwarded-for"
);
if
(
ip
==
null
||
ip
.
length
()
==
0
||
"unknown"
.
equalsIgnoreCase
(
ip
))
{
ip
=
request
.
getHeader
(
"Proxy-Client-IP"
);
}
if
(
ip
==
null
||
ip
.
length
()
==
0
||
"unknown"
.
equalsIgnoreCase
(
ip
))
{
ip
=
request
.
getHeader
(
"WL-Proxy-Client-IP"
);
}
if
(
ip
==
null
||
ip
.
length
()
==
0
||
"unknown"
.
equalsIgnoreCase
(
ip
))
{
ip
=
request
.
getRemoteAddr
();
}
return
ip
;
}
}
src/main/java/io/github/yubincloud/fairywiki/controller/CategoryController.java
浏览文件 @
614ae713
...
...
@@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.*;
import
javax.annotation.Resource
;
import
javax.validation.Valid
;
import
java.util.List
;
@RestController
@RequestMapping
(
"/category"
)
...
...
@@ -19,6 +20,15 @@ public class CategoryController {
@Resource
private
CategoryService
categoryService
;
/**
* 获取全部 Category 的接口
*/
@GetMapping
(
"/all"
)
public
RestfulModel
<
List
<
CategoryQueryRespDto
>>
allCategories
()
{
List
<
CategoryQueryRespDto
>
categoryList
=
categoryService
.
fetchAllCategories
();
return
new
RestfulModel
<>(
ErrorCode
.
SUCCESS
,
""
,
categoryList
);
}
/**
* 对 category 进行查询的接口
* @param categoryQueryReqDto 查询条件的参数
...
...
src/main/java/io/github/yubincloud/fairywiki/service/CategoryService.java
浏览文件 @
614ae713
...
...
@@ -30,6 +30,16 @@ public class CategoryService {
@Resource
private
SnowFlake
snowFlake
;
/**
* 获取全部 Category
*/
public
List
<
CategoryQueryRespDto
>
fetchAllCategories
()
{
CategoryExample
categoryExample
=
new
CategoryExample
();
categoryExample
.
setOrderByClause
(
"sort asc"
);
List
<
Category
>
categoryList
=
categoryMapper
.
selectByExample
(
categoryExample
);
return
CopyUtil
.
copyList
(
categoryList
,
CategoryQueryRespDto
.
class
);
}
/**
* 根据查询条件对数据库中的 category 进行查询并返回查询到的 category
...
...
web/src/views/admin/admin-category.vue
浏览文件 @
614ae713
...
...
@@ -7,19 +7,14 @@
<a-form
layout=
"inline"
:model=
"categoryQueryForm"
@
finish=
"handleQueryFormSubmit
(categoryQueryForm)
"
@
finish=
"handleQueryFormSubmit"
>
<a-form-item>
<a-input
v-model:value=
"categoryQueryForm.name"
placeholder=
"category name"
>
<template
#prefix
><EyeOutlined
style=
"color: rgba(0, 0, 0, 0.25)"
/></
template
>
</a-input>
</a-form-item>
<a-form-item>
<a-button
type=
"primary"
html-type=
"submit"
size=
"large"
:disabled=
"categoryQueryForm.name === ''"
>
查询
</a-button>
...
...
@@ -33,9 +28,8 @@
:columns=
"columns"
:row-key=
"record => record.id"
:data-source=
"categorys"
:pagination=
"
pagination
"
:pagination=
"
false
"
:loading=
"loading"
@
change=
"handleTableChange"
>
<template
#cover
="
{ text: cover }">
<img
v-if=
"cover"
:src=
"cover"
alt=
"avatar"
/>
...
...
@@ -97,11 +91,6 @@ export default defineComponent({
});
const
categorys
=
ref
();
const
pagination
=
ref
({
current
:
1
,
pageSize
:
10
,
total
:
0
});
const
loading
=
ref
(
false
);
const
columns
=
[
...
...
@@ -129,25 +118,15 @@ export default defineComponent({
/**
* 数据查询
**/
const
handleQuery
=
(
queryParams
:
any
)
=>
{
const
handleQuery
=
()
=>
{
loading
.
value
=
true
;
axios
.
get
(
"
/category/query
"
,
{
params
:
{
pageNum
:
queryParams
.
pageNum
,
pageSize
:
queryParams
.
pageSize
,
name
:
queryParams
.
name
,
}
}).
then
((
response
)
=>
{
axios
.
get
(
"
/category/all
"
).
then
((
response
)
=>
{
loading
.
value
=
false
;
const
respData
=
response
.
data
;
if
(
respData
.
code
==
0
)
{
const
pageData
=
respData
.
data
;
categorys
.
value
=
pageData
.
list
;
categorys
.
value
=
respData
.
data
;
// 重置分页按钮
pagination
.
value
.
current
=
queryParams
.
pageNum
;
pagination
.
value
.
total
=
pageData
.
total
;
}
else
{
message
.
error
(
respData
.
msg
);
}
...
...
@@ -157,24 +136,10 @@ export default defineComponent({
/**
* 根据表单提交的数据进行查询
**/
const
handleQueryFormSubmit
=
(
categoryForm
:
CategoryQueryForm
)
=>
{
handleQuery
({
pageNum
:
1
,
pageSize
:
4
,
name
:
categoryForm
.
name
,
});
const
handleQueryFormSubmit
=
()
=>
{
handleQuery
();
};
/**
* 表格点击页码时触发
*/
const
handleTableChange
=
(
pagination
:
any
)
=>
{
console
.
log
(
"
看看自带的分页参数都有啥:
"
,
pagination
);
handleQuery
({
pageNum
:
pagination
.
current
,
pageSize
:
pagination
.
pageSize
});
};
// -------- 表单 ---------
const
category
=
ref
({});
...
...
@@ -190,10 +155,7 @@ export default defineComponent({
}
else
{
message
.
error
(
respData
.
msg
);
}
handleQuery
({
page
:
pagination
.
value
.
current
,
size
:
pagination
.
value
.
pageSize
,
});
handleQuery
();
})
};
...
...
@@ -221,20 +183,14 @@ export default defineComponent({
axios
.
delete
(
"
/category/delete/
"
+
categoryId
).
then
((
response
)
=>
{
const
respData
=
response
.
data
;
if
(
respData
.
code
==
0
)
{
handleQuery
({
page
:
pagination
.
value
.
current
,
size
:
pagination
.
value
.
pageSize
,
});
handleQuery
();
}
});
}
onMounted
(()
=>
{
handleQuery
({
pageNum
:
1
,
pageSize
:
pagination
.
value
.
pageSize
,
});
handleQuery
();
});
return
{
...
...
@@ -243,10 +199,8 @@ export default defineComponent({
wrapperCol
:
{
span
:
14
},
categorys
,
pagination
,
columns
,
loading
,
handleTableChange
,
edit
,
add
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录