pull/3/head
tanghc 4 years ago
parent 725e08d8e7
commit 9c507c8bd3
  1. 9
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/param/ApiArgumentResolver.java
  2. 18
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/util/OpenUtil.java
  3. 7
      sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/Example1001_BaseController.java

@ -181,10 +181,13 @@ public class ApiArgumentResolver implements SopHandlerMethodArgumentResolver {
* @param httpServletRequest * @param httpServletRequest
*/ */
protected void bindUploadFile(Object param, HttpServletRequest httpServletRequest) { protected void bindUploadFile(Object param, HttpServletRequest httpServletRequest) {
if (httpServletRequest instanceof MyServletRequestWrapper) {
httpServletRequest = (HttpServletRequest)((MyServletRequestWrapper) httpServletRequest).getRequest();
}
if (param == null) { if (param == null) {
return; return;
} }
if (this.isMultipartRequest(httpServletRequest)) { if (OpenUtil.isMultipart(httpServletRequest)) {
MultipartHttpServletRequest request = (MultipartHttpServletRequest) httpServletRequest; MultipartHttpServletRequest request = (MultipartHttpServletRequest) httpServletRequest;
Class<?> bizClass = param.getClass(); Class<?> bizClass = param.getClass();
ReflectionUtils.doWithFields(bizClass, field -> { ReflectionUtils.doWithFields(bizClass, field -> {
@ -196,10 +199,6 @@ public class ApiArgumentResolver implements SopHandlerMethodArgumentResolver {
} }
} }
protected boolean isMultipartRequest(HttpServletRequest request) {
return request instanceof MultipartRequest;
}
/** /**
* 获取其它的参数解析器 * 获取其它的参数解析器
* *

@ -14,6 +14,7 @@ import java.net.URLDecoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -23,6 +24,8 @@ import java.util.Set;
@Slf4j @Slf4j
public class OpenUtil { public class OpenUtil {
public static final String MULTIPART = "multipart/";
/** /**
* 将get类型的参数转换成map * 将get类型的参数转换成map
* *
@ -120,4 +123,19 @@ public class OpenUtil {
return serverSign.equals(sign); return serverSign.equals(sign);
} }
/**
* 是否是文件上传请求
*
* @param request 请求
* @return true
*/
public static boolean isMultipart(HttpServletRequest request) {
String contentType = request.getContentType();
// Don't use this filter on GET method
if (contentType == null) {
return false;
}
return contentType.toLowerCase(Locale.ENGLISH).startsWith(MULTIPART);
}
} }

@ -12,7 +12,9 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -83,9 +85,10 @@ public class Example1001_BaseController {
// 忽略验证 // 忽略验证
@ApiOperation(value = "忽略签名验证", notes = "忽略签名验证") @ApiOperation(value = "忽略签名验证", notes = "忽略签名验证")
@Open(value = "story.get.ignore", ignoreValidate = true) @Open(value = "story.get.ignore", ignoreValidate = true)
@RequestMapping("/get/ignore/v1") @RequestMapping(value = "/get/ignore/v1", method = {RequestMethod.GET, RequestMethod.POST})
public StoryResult getStory21(StoryParam story) { public StoryResult getStory21(@RequestBody StoryParam story) {
StoryResult result = new StoryResult(); StoryResult result = new StoryResult();
result.setId((long) story.getId());
result.setName(story.getName() + ", ignoreValidate = true"); result.setName(story.getName() + ", ignoreValidate = true");
return result; return result;
} }

Loading…
Cancel
Save