空属性赋值问题
public class MyBeanUtils {
public static String[] getNullPropertyNames(Object source){
BeanWrapper beanWrapper = new BeanWrapperImpl(source);
PropertyDescriptor[] pds = beanWrapper.getPropertyDescriptors();
List<String> nullPropertyNames = new ArrayList<>();
for(PropertyDescriptor pd:pds){
String propertyName = pd.getName();
if(beanWrapper.getPropertyValue(propertyName)==null){
nullPropertyNames.add(propertyName);
}
}
return nullPropertyNames.toArray(new String[nullPropertyNames.size()]);
}
}
aspect日志
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Pointcut("execution(* com.lin.news.web.*.*(..))")
public void log(){
}
@Before("log()")
public void deBefore(JoinPoint joinPoint){
//获取request
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request =attributes.getRequest();
//获得url和ip
// String url =request.getRequestURI().toString(); //不打印localhost:8080
String url =request.getRequestURL().toString(); //打印localhost:8080
String ip = request.getRemoteAddr();
String classMethod =joinPoint.getSignature().getDeclaringTypeName()+".";
Object[] args = joinPoint.getArgs();
RequestLog requestLog = new RequestLog(url,ip,classMethod,args);
logger.info("Request:{}",requestLog);
logger.info("-------doBefore-------");
}
@After("log()")
public void doAfter(){
logger.info("-------doAfter-------");
}
@AfterReturning(returning = "result",pointcut = "log()")
public void adAfterReturn(Object result){
logger.info("result:{}"+result);
}
可以打印出路径以及访问页面