🐛 can not cast to JSONObject 问题修复

This commit is contained in:
ronger 2022-05-27 14:40:08 +08:00
parent cc23959133
commit b281703bac
2 changed files with 20 additions and 5 deletions

View File

@ -75,11 +75,21 @@ public class AuthorshipAspect {
isArticle = false; isArticle = false;
} }
HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
String idArticle = ""; String idArticle;
Integer idAuthor = 0; Integer idAuthor = 0;
if (isAjax(request)) { if (isAjax(request)) {
Object[] objects = joinPoint.getArgs(); Object[] objects = joinPoint.getArgs();
JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(objects[0])); JSONObject jsonObject;
if (objects[0] instanceof Integer) {
jsonObject = new JSONObject();
if (isArticle) {
jsonObject.put("idArticle", objects[0].toString());
} else {
jsonObject.put("idPortfolio", objects[0].toString());
}
} else {
jsonObject = JSONObject.parseObject(JSON.toJSONString(objects[0]));
}
if (Objects.nonNull(jsonObject)) { if (Objects.nonNull(jsonObject)) {
if (isArticle) { if (isArticle) {
idArticle = jsonObject.getString("idArticle"); idArticle = jsonObject.getString("idArticle");

View File

@ -54,10 +54,15 @@ public class SecurityAspect {
String idUser = ""; String idUser = "";
if (isAjax(request)) { if (isAjax(request)) {
Object[] objects = joinPoint.getArgs(); Object[] objects = joinPoint.getArgs();
JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(objects[0])); JSONObject jsonObject;
if (objects[0] instanceof Integer) {
idUser = objects[0].toString();
} else {
jsonObject = JSONObject.parseObject(JSON.toJSONString(objects[0]));
if (Objects.nonNull(jsonObject)) { if (Objects.nonNull(jsonObject)) {
idUser = jsonObject.getString("idUser"); idUser = jsonObject.getString("idUser");
} }
}
} else { } else {
Map params = getParams(request); Map params = getParams(request);
if (params.isEmpty()) { if (params.isEmpty()) {