Authored by cille

update: fix bug

1 package com.begete.web.controller.tool; 1 package com.begete.web.controller.tool;
2 2
3 -import java.util.ArrayList;  
4 -import java.util.LinkedHashMap;  
5 -import java.util.List;  
6 -import java.util.Map;  
7 -import org.springframework.web.bind.annotation.DeleteMapping;  
8 -import org.springframework.web.bind.annotation.GetMapping;  
9 -import org.springframework.web.bind.annotation.PathVariable;  
10 -import org.springframework.web.bind.annotation.PostMapping;  
11 -import org.springframework.web.bind.annotation.PutMapping;  
12 -import org.springframework.web.bind.annotation.RequestMapping;  
13 -import org.springframework.web.bind.annotation.RestController; 3 +import java.util.*;
  4 +
  5 +import com.begete.common.annotation.RepeatSubmit;
  6 +import org.springframework.web.bind.annotation.*;
14 import com.begete.common.core.controller.BaseController; 7 import com.begete.common.core.controller.BaseController;
15 import com.begete.common.core.domain.AjaxResult; 8 import com.begete.common.core.domain.AjaxResult;
16 import com.begete.common.utils.StringUtils; 9 import com.begete.common.utils.StringUtils;
@@ -36,6 +29,15 @@ public class TestController extends BaseController @@ -36,6 +29,15 @@ public class TestController extends BaseController
36 users.put(2, new UserEntity(2, "ry", "admin123", "15666666666")); 29 users.put(2, new UserEntity(2, "ry", "admin123", "15666666666"));
37 } 30 }
38 31
  32 +
  33 + @ApiOperation("测试重复提交")
  34 + @RepeatSubmit
  35 + @PostMapping("/testRepeat")
  36 + public AjaxResult testRepeat(@RequestBody HashMap map) throws InterruptedException {
  37 + Thread.sleep(2000);
  38 + return AjaxResult.success(map);
  39 + }
  40 +
39 @ApiOperation("获取用户列表") 41 @ApiOperation("获取用户列表")
40 @GetMapping("/list") 42 @GetMapping("/list")
41 public AjaxResult userList() 43 public AjaxResult userList()
@@ -24,13 +24,28 @@ public class RepeatableFilter implements Filter @@ -24,13 +24,28 @@ public class RepeatableFilter implements Filter
24 24
25 } 25 }
26 26
  27 + public static void main(String[] args) {
  28 +// System.out.println(
  29 +// "application/json;charset=UTF-8".contains(MediaType.APPLICATION_JSON_VALUE)
  30 +// );
  31 + System.out.println(
  32 + StringUtils.equalsAnyIgnoreCase( "application/json", MediaType.APPLICATION_JSON_VALUE)
  33 + );
  34 + System.out.println(
  35 + StringUtils.equalsAnyIgnoreCase( "application/json;charset=UTF-8", MediaType.APPLICATION_JSON_VALUE)
  36 + );
  37 + }
  38 +
27 @Override 39 @Override
28 public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) 40 public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
29 throws IOException, ServletException 41 throws IOException, ServletException
30 { 42 {
31 ServletRequest requestWrapper = null; 43 ServletRequest requestWrapper = null;
32 if (request instanceof HttpServletRequest 44 if (request instanceof HttpServletRequest
33 - && StringUtils.equalsAnyIgnoreCase(request.getContentType(), MediaType.APPLICATION_JSON_VALUE)) 45 + && request.getContentType() != null
  46 + && request.getContentType().contains(MediaType.APPLICATION_JSON_VALUE)
  47 +// && StringUtils.equalsAnyIgnoreCase(request.getContentType(), MediaType.APPLICATION_JSON_VALUE)
  48 + )
34 { 49 {
35 requestWrapper = new RepeatedlyRequestWrapper((HttpServletRequest) request, response); 50 requestWrapper = new RepeatedlyRequestWrapper((HttpServletRequest) request, response);
36 } 51 }