Hello everyone, I am Spring CITY IT, here to share with you, how to generate login captcha in Springboot picture

The introduction of the jar package

<dependency>
            <groupId>com.github.whvcse</groupId>
            <artifactId>easy-captcha</artifactId>
        </dependency>
Copy the code

Set the size of the image generated by the verification code

LoginCode: expiration: 2 codeKey: "validate_code" Width: 108 height: 28 length: 4Copy the code

Background verification code interface

@apiOperation (" Obtain verification code") @getMapping (value = "/code") public DataResponseBody getCode() {Captcha Captcha = new SpecCaptcha(width, height, length); String createText = captcha.text(); String uuid = codeKey + IdUtil.simpleUUID(); // Save redisutils. set(uuid, createText, expiration, timeunit.minutes); Map<String, Object> imgResult = new HashMap<String, Object>(4) {{put("img", captcha.tobase64 ()); put("uuid", uuid); }}; return new DataResponseBody(imgResult); }Copy the code

The end

The code is very simple, I hope to help you, there is a good technology to share with you, be there or be square