Skip to content

Commit

Permalink
部分工具类实现改用hutool工具包
Browse files Browse the repository at this point in the history
  • Loading branch information
macrozheng committed Apr 29, 2019
1 parent 0e347c3 commit ea0b1a0
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 142 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.macro.mall.component;

import cn.hutool.json.JSONUtil;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.util.JsonUtil;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;
Expand All @@ -21,7 +21,7 @@ public class RestAuthenticationEntryPoint implements AuthenticationEntryPoint {
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json");
response.getWriter().println(JsonUtil.objectToJson(CommonResult.unauthorized(authException.getMessage())));
response.getWriter().println(JSONUtil.parse(CommonResult.unauthorized(authException.getMessage())));
response.getWriter().flush();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.macro.mall.component;

import cn.hutool.json.JSONUtil;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.util.JsonUtil;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;
Expand All @@ -23,7 +23,7 @@ public void handle(HttpServletRequest request,
AccessDeniedException e) throws IOException, ServletException {
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json");
response.getWriter().println(JsonUtil.objectToJson(CommonResult.forbidden(e.getMessage())));
response.getWriter().println(JSONUtil.parse(CommonResult.forbidden(e.getMessage())));
response.getWriter().flush();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.macro.mall.component;

import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.URLUtil;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import com.macro.mall.bo.WebLog;
import com.macro.mall.util.JsonUtil;
import com.macro.mall.util.RequestUtil;
import io.swagger.annotations.ApiOperation;
import net.logstash.logback.marker.Markers;
import org.aspectj.lang.JoinPoint;
Expand Down Expand Up @@ -68,7 +70,8 @@ public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
webLog.setDescription(log.value());
}
long endTime = System.currentTimeMillis();
webLog.setBasePath(RequestUtil.getBasePath(request));
String urlStr = request.getRequestURL().toString();
webLog.setBasePath(StrUtil.removeSuffix(urlStr, URLUtil.url(urlStr).getPath()));
webLog.setIp(request.getRemoteUser());
webLog.setMethod(request.getMethod());
webLog.setParameter(getParameter(method, joinPoint.getArgs()));
Expand All @@ -83,8 +86,8 @@ public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
logMap.put("parameter",webLog.getParameter());
logMap.put("spendTime",webLog.getSpendTime());
logMap.put("description",webLog.getDescription());
// LOGGER.info("{}", JsonUtil.objectToJson(webLog));
LOGGER.info(Markers.appendEntries(logMap),JsonUtil.objectToJson(webLog));
// LOGGER.info("{}", JSONUtil.parse(webLog));
LOGGER.info(Markers.appendEntries(logMap), JSONUtil.parse(webLog).toString());
return result;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.macro.mall.service.impl;

import cn.hutool.json.JSONUtil;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.common.utils.BinaryUtil;
import com.aliyun.oss.model.MatchMode;
import com.aliyun.oss.model.PolicyConditions;
import com.macro.mall.dto.OssCallbackParam;
import com.macro.mall.dto.OssCallbackResult;
import com.macro.mall.dto.OssPolicyResult;
import com.macro.mall.service.OssService;
Expand Down Expand Up @@ -69,7 +71,7 @@ public OssPolicyResult policy() {
byte[] binaryData = postPolicy.getBytes("utf-8");
String policy = BinaryUtil.toBase64String(binaryData);
String signature = ossClient.calculatePostSignature(postPolicy);
// String callbackData = BinaryUtil.toBase64String(JsonUtil.objectToJson(callback).getBytes("utf-8"));
// String callbackData = BinaryUtil.toBase64String(JSONUtil.parse(callback).toString().getBytes("utf-8"));
// 返回结果
result.setAccessKeyId(ossClient.getCredentialsProvider().getCredentials().getAccessKeyId());
result.setPolicy(policy);
Expand Down
62 changes: 0 additions & 62 deletions mall-admin/src/main/java/com/macro/mall/util/JsonUtil.java

This file was deleted.

68 changes: 0 additions & 68 deletions mall-admin/src/main/java/com/macro/mall/util/RequestUtil.java

This file was deleted.

4 changes: 2 additions & 2 deletions mall-admin/src/test/com/macro/mall/PmsDaoTests.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.macro.mall;


import cn.hutool.json.JSONUtil;
import com.macro.mall.dao.PmsMemberPriceDao;
import com.macro.mall.dao.PmsProductDao;
import com.macro.mall.dto.PmsProductResult;
import com.macro.mall.model.PmsMemberPrice;
import com.macro.mall.util.JsonUtil;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -48,7 +48,7 @@ public void testInsertBatch(){
@Test
public void testGetProductUpdateInfo(){
PmsProductResult productResult = productDao.getUpdateInfo(7L);
String json = JsonUtil.objectToJson(productResult);
String json = JSONUtil.parse(productResult).toString();
LOGGER.info(json);
}
}
6 changes: 6 additions & 0 deletions mall-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
<artifactId>spring-data-commons</artifactId>
<version>2.1.5.RELEASE</version>
</dependency>
<!--Hutool Java工具包-->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>4.5.7</version>
</dependency>
</dependencies>

</project>

0 comments on commit ea0b1a0

Please sign in to comment.