prevents form or request multi-submits.
includes dependency in pom.xml
notes: don't publish maven central yet, you can install by mvn install
and then using following pom dependency.
<dependency>
<groupId>com.codimiracle.web</groupId>
<artifactId>request-identifier</artifactId>
<version>0.0.1-snapshot</version>
</dependency>
- Request infrequent repeat
- Request only once (based on redis)
- Checking result and running custom logic (implements
ResultHandler
)
using @NonRepeatable
annotate in controller layer:
-
only once
@NonRepeatable public String onlyOnce(String data) { return "Your submission is accepted."; }
-
don't repeat in one seconds interval.
@NonRepeatable(interval = NonRepeatable.DEFAULT_INTERVAL) public String defaultInterval(String data) { return "Your submission is accepted."; }
-
custom interval
@NonRepeatable(interval = 2000) public String customInterval(String data) { return "Your submission is accepted."; }
-
using specified request parameter
parameter value will retrieve from HttpServletRequest#getParameterValues();
@GetMapping("/hello") @NonRepeatable(strategy = IdentifierStrategy.REQUEST_PARAMETER, parameterName = "request_id") public String customInterval(String data) { return "Your submission is accepted."; }
-
using all parameters in request
@GetMapping("/hi") @NonRepeatable(strategy = IdentifierStrategy.REQUEST_PARAMETER) public String customInterval(String data) { return "Your submission is accepted."; }