//定义一个fastJson拦截器
public class FastJsonFilter {
@Around("execution(* com.xxx.xxx.*(..))")
public Object around(ProceedingJoinPoint pjp) throws Throwable {
//获取目标方法的参数
Object[] args = pjp.getArgs();
//循环遍历参数
for (Object arg : args) {
//判断参数是否为文件类型
if (arg instanceof MultipartFile) {
//如果是,则调用fastjson的process方法进行处理
String json = JSON.toJSONString(arg, SerializerFeature.WriteMapNullValue);
JSONObject jsonObject = JSONObject.parseObject(json);
jsonObject = JSON.parseObject(jsonObject.getString("file"), JSONObject.class);
arg = JSON.parseObject(jsonObject.toString(), MultipartFile.class);
}
}
return pjp.proceed(args);
}
}
java中fastJson如何在aop过滤文件上传对象
最新推荐文章于 2023-07-23 07:08:29 发布
该代码定义了一个FastJson拦截器,用于处理执行com.xxx.xxx.*包下方法的参数。它遍历方法参数,检查并转化MultipartFile对象,利用FastJson的toJSONString和parseObject方法进行序列化和反序列化操作,确保文件类型的参数能被正确处理。
摘要由CSDN通过智能技术生成