1, tools
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. Background
//getYZM @RequestMapping("/getYZM/{phone}") public Object getYZM(@PathVariable String phone){ return MessageUtil.creatYZM(); }
3, the front desk
getYZM function () { Alert ( "returns a verification code" ) var Phone = $ ( "Phone #" ) .val () $ .post ( "HTTP: // localhost: 8080 / getYZM /" + Phone, function (obj ) { Alert (obj) } ) }