mirror of https://gitee.com/y_project/RuoYi.git
Pre Merge pull request !435 from srma112233/master
commit
9ad69c9850
|
@ -0,0 +1,20 @@
|
||||||
|
package com.ruoyi.common.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 忽略当前字段
|
||||||
|
* 如果注解用在类上,忽略当前类
|
||||||
|
* 如果注解用在属性上,忽略当前属性
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target({ElementType.FIELD, ElementType.TYPE})
|
||||||
|
public @interface IgnoreTarget {
|
||||||
|
/**
|
||||||
|
* 使用目的,默认为空
|
||||||
|
*/
|
||||||
|
String[] target() default {};
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
package com.ruoyi.common.utils;
|
||||||
|
|
||||||
|
import com.ruoyi.common.annotation.IgnoreTarget;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类描述
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class IgnoreFieldsUtils {
|
||||||
|
public static String[] getIgnoreFields(Object o, String target) {
|
||||||
|
Field[] fields = o.getClass().getDeclaredFields();
|
||||||
|
if (Objects.isNull(fields) || fields.length == 0) {
|
||||||
|
return new String[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> list = new ArrayList<>();
|
||||||
|
for (int i = 0; i < fields.length; i++) {
|
||||||
|
Field field = fields[i];
|
||||||
|
if (field.isAnnotationPresent(IgnoreTarget.class)) {
|
||||||
|
String[] t = field.getAnnotation(IgnoreTarget.class).target();
|
||||||
|
if (Objects.isNull(t) || t.length == 0) {
|
||||||
|
list.add(field.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Arrays.asList(t).contains(target)) {
|
||||||
|
list.add(field.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return list.toArray(new String[list.size()]);
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,8 +2,12 @@ package com.ruoyi.framework.aspectj;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import com.ruoyi.common.annotation.IgnoreTarget;
|
||||||
|
import com.ruoyi.common.utils.IgnoreFieldsUtils;
|
||||||
import org.aspectj.lang.JoinPoint;
|
import org.aspectj.lang.JoinPoint;
|
||||||
import org.aspectj.lang.annotation.AfterReturning;
|
import org.aspectj.lang.annotation.AfterReturning;
|
||||||
import org.aspectj.lang.annotation.AfterThrowing;
|
import org.aspectj.lang.annotation.AfterThrowing;
|
||||||
|
@ -194,27 +198,29 @@ public class LogAspect
|
||||||
/**
|
/**
|
||||||
* 参数拼装
|
* 参数拼装
|
||||||
*/
|
*/
|
||||||
private String argsArrayToString(Object[] paramsArray)
|
private String argsArrayToString(Object[] paramsArray) {
|
||||||
{
|
StringBuffer sb = new StringBuffer();
|
||||||
String params = "";
|
if (Objects.isNull(paramsArray) || paramsArray.length <= 0) {
|
||||||
if (paramsArray != null && paramsArray.length > 0)
|
return StringUtils.EMPTY;
|
||||||
{
|
}
|
||||||
for (Object o : paramsArray)
|
|
||||||
{
|
for (Object o : paramsArray) {
|
||||||
if (StringUtils.isNotNull(o) && !isFilterObject(o))
|
if (Objects.isNull(o) || isFilterObject(o)) {
|
||||||
{
|
continue;
|
||||||
try
|
}
|
||||||
{
|
|
||||||
Object jsonObj = JSONObject.toJSONString(o, excludePropertyPreFilter());
|
try {
|
||||||
params += jsonObj.toString() + " ";
|
PropertyPreFilters.MySimplePropertyPreFilter filter = excludePropertyPreFilter();
|
||||||
}
|
|
||||||
catch (Exception e)
|
// 过滤注解需要忽略的字段
|
||||||
{
|
filter.addExcludes(IgnoreFieldsUtils.getIgnoreFields(o, "LogAspect"));
|
||||||
}
|
sb.append(JSONObject.toJSONString(o, filter));
|
||||||
}
|
} catch (Exception e) {
|
||||||
|
//TODO something
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return params.trim();
|
|
||||||
|
return sb.toString().trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -248,7 +254,8 @@ public class LogAspect
|
||||||
return entry.getValue() instanceof MultipartFile;
|
return entry.getValue() instanceof MultipartFile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return o instanceof MultipartFile || o instanceof HttpServletRequest || o instanceof HttpServletResponse
|
return o instanceof MultipartFile || o instanceof HttpServletRequest || o instanceof HttpServletResponse
|
||||||
|| o instanceof BindingResult;
|
|| o instanceof BindingResult || clazz.isAnnotationPresent(IgnoreTarget.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue