# repeat-submit-spring-boot-starter **Repository Path**: xiagen/repeat-submit-spring-boot-starter ## Basic Information - **Project Name**: repeat-submit-spring-boot-starter - **Description**: 用于表单防重复提交,及接口幂等性处理 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 4 - **Forks**: 0 - **Created**: 2021-11-25 - **Last Updated**: 2022-09-16 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README 1、测试类 ```java package com.repeat.submit.test; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.web.client.RestTemplate; import java.nio.charset.StandardCharsets; import java.util.concurrent.CountDownLatch; /** * @author : XiaGen * @Description: TODO * @date Date : 2021/11/25 */ public class JavaMain { public static void main(String[] args) { int a = 10; CountDownLatch countDownLatch = new CountDownLatch(a); for (int i = 0; i < a; i++) { RestTemplate restTemplate = new RestTemplate(); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentType(MediaType.APPLICATION_JSON); httpHeaders.set("token","1321"); HttpEntity httpEntity = new HttpEntity<>("{\n" + "\t\"avatarUrl\": \"\",\n" + "\t\"birthday\": \"\",\n" + "\t\"email\": \"\",\n" + "\t\"idCardNumber\": \"\",\n" + "\t\"idCardPhotoBack\": \"\",\n" + "\t\"idCardPhotoFront\": \"\",\n" + "\t\"idCardType\": 0,\n" + "\t\"idCardValidity\": \"\",\n" + "\t\"minappletPhone\": {},\n" + "\t\"mobile\": \"\",\n" + "\t\"nickName\": \"\",\n" + "\t\"oauthType\": 0,\n" + "\t\"openId\": \"\",\n" + "\t\"realName\": \"\",\n" + "\t\"remark\": \"\",\n" + "\t\"sexKey\": \"\",\n" + "\t\"systemId\": 0,\n" + "\t\"userId\": 0,\n" + "\t\"userName\": \"\"\n" + "}",httpHeaders); new Thread(()->{ try { countDownLatch.await(); } catch (InterruptedException e) { e.printStackTrace(); } String s = restTemplate.postForObject("http://192.168.1.77:8460/client/user/test", httpEntity, String.class); System.out.println(new String(s.getBytes(StandardCharsets.ISO_8859_1))); }).start(); countDownLatch.countDown(); } } } ``` 2、响应结果 ```text 17:40:23.392 [Thread-2] DEBUG org.springframework.web.client.RestTemplate - HTTP POST http://192.168.1.77:8460/client/user/test 17:40:23.392 [Thread-9] DEBUG org.springframework.web.client.RestTemplate - HTTP POST http://192.168.1.77:8460/client/user/test 17:40:23.392 [Thread-5] DEBUG org.springframework.web.client.RestTemplate - HTTP POST http://192.168.1.77:8460/client/user/test 17:40:23.392 [Thread-8] DEBUG org.springframework.web.client.RestTemplate - HTTP POST http://192.168.1.77:8460/client/user/test 17:40:23.392 [Thread-1] DEBUG org.springframework.web.client.RestTemplate - HTTP POST http://192.168.1.77:8460/client/user/test 17:40:23.392 [Thread-4] DEBUG org.springframework.web.client.RestTemplate - HTTP POST http://192.168.1.77:8460/client/user/test 17:40:23.392 [Thread-7] DEBUG org.springframework.web.client.RestTemplate - HTTP POST http://192.168.1.77:8460/client/user/test 17:40:23.392 [Thread-6] DEBUG org.springframework.web.client.RestTemplate - HTTP POST http://192.168.1.77:8460/client/user/test 17:40:23.392 [Thread-3] DEBUG org.springframework.web.client.RestTemplate - HTTP POST http://192.168.1.77:8460/client/user/test 17:40:23.392 [Thread-0] DEBUG org.springframework.web.client.RestTemplate - HTTP POST http://192.168.1.77:8460/client/user/test 17:40:23.409 [Thread-5] DEBUG org.springframework.web.client.RestTemplate - Accept=[text/plain, application/json, application/*+json, */*] 17:40:23.409 [Thread-2] DEBUG org.springframework.web.client.RestTemplate - Accept=[text/plain, application/json, application/*+json, */*] 17:40:23.409 [Thread-1] DEBUG org.springframework.web.client.RestTemplate - Accept=[text/plain, application/json, application/*+json, */*] 17:40:23.409 [Thread-7] DEBUG org.springframework.web.client.RestTemplate - Accept=[text/plain, application/json, application/*+json, */*] 17:40:23.409 [Thread-6] DEBUG org.springframework.web.client.RestTemplate - Accept=[text/plain, application/json, application/*+json, */*] 17:40:23.409 [Thread-8] DEBUG org.springframework.web.client.RestTemplate - Accept=[text/plain, application/json, application/*+json, */*] 17:40:23.409 [Thread-9] DEBUG org.springframework.web.client.RestTemplate - Accept=[text/plain, application/json, application/*+json, */*] 17:40:23.409 [Thread-3] DEBUG org.springframework.web.client.RestTemplate - Accept=[text/plain, application/json, application/*+json, */*] 17:40:23.409 [Thread-0] DEBUG org.springframework.web.client.RestTemplate - Accept=[text/plain, application/json, application/*+json, */*] 17:40:23.409 [Thread-4] DEBUG org.springframework.web.client.RestTemplate - Accept=[text/plain, application/json, application/*+json, */*] 17:40:23.415 [Thread-0] DEBUG org.springframework.web.client.RestTemplate - Writing [{ "avatarUrl": "", "birthday": "", "email": "", "idCardNumber": "", "idCardPhotoBack": "", "idCardPhotoFront": "", "idCardType": 0, "idCardValidity": "", "minappletPhone": {}, "mobile": "", "nickName": "", "oauthType": 0, "openId": "", "realName": "", "remark": "", "sexKey": "", "systemId": 0, "userId": 0, "userName": "" }] as "application/json" 17:40:23.415 [Thread-7] DEBUG org.springframework.web.client.RestTemplate - Writing [{ "avatarUrl": "", "birthday": "", "email": "", "idCardNumber": "", "idCardPhotoBack": "", "idCardPhotoFront": "", "idCardType": 0, "idCardValidity": "", "minappletPhone": {}, "mobile": "", "nickName": "", "oauthType": 0, "openId": "", "realName": "", "remark": "", "sexKey": "", "systemId": 0, "userId": 0, "userName": "" }] as "application/json" 17:40:23.415 [Thread-5] DEBUG org.springframework.web.client.RestTemplate - Writing [{ "avatarUrl": "", "birthday": "", "email": "", "idCardNumber": "", "idCardPhotoBack": "", "idCardPhotoFront": "", "idCardType": 0, "idCardValidity": "", "minappletPhone": {}, "mobile": "", "nickName": "", "oauthType": 0, "openId": "", "realName": "", "remark": "", "sexKey": "", "systemId": 0, "userId": 0, "userName": "" }] as "application/json" 17:40:23.415 [Thread-3] DEBUG org.springframework.web.client.RestTemplate - Writing [{ "avatarUrl": "", "birthday": "", "email": "", "idCardNumber": "", "idCardPhotoBack": "", "idCardPhotoFront": "", "idCardType": 0, "idCardValidity": "", "minappletPhone": {}, "mobile": "", "nickName": "", "oauthType": 0, "openId": "", "realName": "", "remark": "", "sexKey": "", "systemId": 0, "userId": 0, "userName": "" }] as "application/json" 17:40:23.415 [Thread-4] DEBUG org.springframework.web.client.RestTemplate - Writing [{ "avatarUrl": "", "birthday": "", "email": "", "idCardNumber": "", "idCardPhotoBack": "", "idCardPhotoFront": "", "idCardType": 0, "idCardValidity": "", "minappletPhone": {}, "mobile": "", "nickName": "", "oauthType": 0, "openId": "", "realName": "", "remark": "", "sexKey": "", "systemId": 0, "userId": 0, "userName": "" }] as "application/json" 17:40:23.415 [Thread-8] DEBUG org.springframework.web.client.RestTemplate - Writing [{ "avatarUrl": "", "birthday": "", "email": "", "idCardNumber": "", "idCardPhotoBack": "", "idCardPhotoFront": "", "idCardType": 0, "idCardValidity": "", "minappletPhone": {}, "mobile": "", "nickName": "", "oauthType": 0, "openId": "", "realName": "", "remark": "", "sexKey": "", "systemId": 0, "userId": 0, "userName": "" }] as "application/json" 17:40:23.415 [Thread-6] DEBUG org.springframework.web.client.RestTemplate - Writing [{ "avatarUrl": "", "birthday": "", "email": "", "idCardNumber": "", "idCardPhotoBack": "", "idCardPhotoFront": "", "idCardType": 0, "idCardValidity": "", "minappletPhone": {}, "mobile": "", "nickName": "", "oauthType": 0, "openId": "", "realName": "", "remark": "", "sexKey": "", "systemId": 0, "userId": 0, "userName": "" }] as "application/json" 17:40:23.415 [Thread-9] DEBUG org.springframework.web.client.RestTemplate - Writing [{ "avatarUrl": "", "birthday": "", "email": "", "idCardNumber": "", "idCardPhotoBack": "", "idCardPhotoFront": "", "idCardType": 0, "idCardValidity": "", "minappletPhone": {}, "mobile": "", "nickName": "", "oauthType": 0, "openId": "", "realName": "", "remark": "", "sexKey": "", "systemId": 0, "userId": 0, "userName": "" }] as "application/json" 17:40:23.415 [Thread-1] DEBUG org.springframework.web.client.RestTemplate - Writing [{ "avatarUrl": "", "birthday": "", "email": "", "idCardNumber": "", "idCardPhotoBack": "", "idCardPhotoFront": "", "idCardType": 0, "idCardValidity": "", "minappletPhone": {}, "mobile": "", "nickName": "", "oauthType": 0, "openId": "", "realName": "", "remark": "", "sexKey": "", "systemId": 0, "userId": 0, "userName": "" }] as "application/json" 17:40:23.415 [Thread-2] DEBUG org.springframework.web.client.RestTemplate - Writing [{ "avatarUrl": "", "birthday": "", "email": "", "idCardNumber": "", "idCardPhotoBack": "", "idCardPhotoFront": "", "idCardType": 0, "idCardValidity": "", "minappletPhone": {}, "mobile": "", "nickName": "", "oauthType": 0, "openId": "", "realName": "", "remark": "", "sexKey": "", "systemId": 0, "userId": 0, "userName": "" }] as "application/json" 17:40:23.433 [Thread-8] DEBUG org.springframework.web.client.RestTemplate - Response 200 OK 17:40:23.433 [Thread-5] DEBUG org.springframework.web.client.RestTemplate - Response 200 OK 17:40:23.433 [Thread-3] DEBUG org.springframework.web.client.RestTemplate - Response 200 OK 17:40:23.433 [Thread-4] DEBUG org.springframework.web.client.RestTemplate - Response 200 OK 17:40:23.433 [Thread-6] DEBUG org.springframework.web.client.RestTemplate - Response 200 OK 17:40:23.434 [Thread-3] DEBUG org.springframework.web.client.RestTemplate - Reading to [java.lang.String] as "application/json" 17:40:23.434 [Thread-6] DEBUG org.springframework.web.client.RestTemplate - Reading to [java.lang.String] as "application/json" 17:40:23.434 [Thread-4] DEBUG org.springframework.web.client.RestTemplate - Reading to [java.lang.String] as "application/json" 17:40:23.434 [Thread-8] DEBUG org.springframework.web.client.RestTemplate - Reading to [java.lang.String] as "application/json" 17:40:23.434 [Thread-5] DEBUG org.springframework.web.client.RestTemplate - Reading to [java.lang.String] as "application/json" {"msg":"请勿重复提交","code":-2} {"msg":"请勿重复提交","code":-2} {"msg":"请勿重复提交","code":-2} {"msg":"请勿重复提交","code":-2} {"msg":"请勿重复提交","code":-2} 17:40:23.441 [Thread-1] DEBUG org.springframework.web.client.RestTemplate - Response 200 OK 17:40:23.441 [Thread-0] DEBUG org.springframework.web.client.RestTemplate - Response 200 OK 17:40:23.441 [Thread-9] DEBUG org.springframework.web.client.RestTemplate - Response 200 OK 17:40:23.441 [Thread-1] DEBUG org.springframework.web.client.RestTemplate - Reading to [java.lang.String] as "application/json" 17:40:23.441 [Thread-2] DEBUG org.springframework.web.client.RestTemplate - Response 200 OK 17:40:23.441 [Thread-0] DEBUG org.springframework.web.client.RestTemplate - Reading to [java.lang.String] as "application/json" 17:40:23.441 [Thread-9] DEBUG org.springframework.web.client.RestTemplate - Reading to [java.lang.String] as "application/json" 17:40:23.441 [Thread-2] DEBUG org.springframework.web.client.RestTemplate - Reading to [java.lang.String] as "application/json" {"msg":"请勿重复提交","code":-2} {"msg":"请勿重复提交","code":-2} {"msg":"请勿重复提交","code":-2} {"msg":"请勿重复提交","code":-2} 17:40:23.582 [Thread-7] DEBUG org.springframework.web.client.RestTemplate - Response 200 OK 17:40:23.582 [Thread-7] DEBUG org.springframework.web.client.RestTemplate - Reading to [java.lang.String] as "application/json" {"code":0,"msg":"成功[0]","data":"0","success":true,"fail":false} ``` 4、如何使用 ```text com.repeat.submit repeat-submit-spring-boot-starter 1.0.0 ``` 5、示列 ![img_1.png](img_1.png) 6、配置http中header的key name,默认key name为token,建议使用系统身份认证token的key,主要用于表示用户标识 ![img.png](img.png) 7、说明 ```text 防重复提交生成key存储在redis当中,所以请在项目中配置spring-boot-starter-data-redis ```