提交 614ae713 编写于 作者: yubinCloud's avatar yubinCloud

7-3 使分类管理不再显示分页

上级 1da34f09
//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;
}
}
......@@ -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 查询条件的参数
......
......@@ -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
......
......@@ -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.
先完成此消息的编辑!
想要评论请 注册