• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

Spring-boot注册验证码

武飞扬头像
struggling_sworm
帮助1

一、导入依赖

  1.  
    <dependency>
  2.  
    <groupId>com.github.penggle</groupId>
  3.  
    <artifactId>kaptcha</artifactId>
  4.  
    <version>2.3.2</version>
  5.  
    </dependency>

二、配置类(Application.java)

  1.  
    package com.woniuxy.springbootdemo.utils;
  2.  
     
  3.  
    import com.谷歌.code.kaptcha.impl.DefaultKaptcha;
  4.  
    import com.谷歌.code.kaptcha.util.Config;
  5.  
    import org.mybatis.spring.annotation.MapperScan;
  6.  
    import org.springframework.boot.SpringApplication;
  7.  
    import org.springframework.boot.autoconfigure.SpringBootApplication;
  8.  
    import org.springframework.context.annotation.Bean;
  9.  
     
  10.  
    import java.util.Properties;
  11.  
     
  12.  
    //@ServletComponentScan(basePackages = "")
  13.  
    @SpringBootApplication
  14.  
    @MapperScan(basePackages = "com.woniuxy.springbootdemo.mappers")
  15.  
    public class Application {
  16.  
     
  17.  
    public static void main(String[] args) {
  18.  
    SpringApplication.run(Application.class, args);
  19.  
    }
  20.  
    @Bean
  21.  
    public DefaultKaptcha getDefaultKaptcha() {
  22.  
    DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
  23.  
    Properties properties = new Properties();
  24.  
    // 图片边框
  25.  
    properties.setProperty("kaptcha.border", "yes");
  26.  
    // 边框颜色
  27.  
    properties.setProperty("kaptcha.border.color", "105,179,90");
  28.  
    // 字体颜色
  29.  
    properties.setProperty("kaptcha.textproducer.font.color", "red");
  30.  
    // 图片宽
  31.  
    properties.setProperty("kaptcha.image.width", "86");
  32.  
    // 图片高
  33.  
    properties.setProperty("kaptcha.image.height", "40");
  34.  
    // 字体大小
  35.  
    properties.setProperty("kaptcha.textproducer.font.size", "30");
  36.  
    // session key
  37.  
    properties.setProperty("kaptcha.session.key", "code");
  38.  
    // 验证码长度
  39.  
    properties.setProperty("kaptcha.textproducer.char.length", "4");
  40.  
    // 字体
  41.  
    properties.setProperty("kaptcha.textproducer.font.names", "宋体,楷体,微软雅黑");
  42.  
     
  43.  
    properties.setProperty("kaptcha.noise.color", "35,37,38");
  44.  
     
  45.  
    Config config = new Config(properties);
  46.  
    defaultKaptcha.setConfig(config);
  47.  
     
  48.  
    return defaultKaptcha;
  49.  
    }
  50.  
    }
学新通

三、templates端

<img alt="验证码,点击图片更换" th:src="@{/member/captcha}" width="86" height="40">

四、效果

学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgfjkfk
系列文章
更多 icon
同类精品
更多 icon
继续加载