1、工具类

package com.bw.utils;
/**
 * 验证码生成器(4位数)
 */
import java.util.Random;

public class MessageUtil {
    public static String  creatYZM() {
        String a="";
        Random random = new Random();

        for (int i = 0; i < 4 ;i++) {
        a+=    random.nextInt(10);

        }
        System.out.println(a);
        return a;

    }


}

2、后台

    //getYZM
    @RequestMapping("/getYZM/{phone}")
    public Object getYZM(@PathVariable String phone){
        return MessageUtil.creatYZM();


    }

3、前台

  function getYZM(){

        alert("返回一个验证码")
        var phone=$("#phone").val()

        $.post(

                "http://localhost:8080/getYZM/"+phone,
                function(obj){

                    alert(obj)

                }

                )

    }
12-16 08:19
查看更多