在实现发送短信验证码功能的时候, @RequestMapping配置了多个路径。
代码如下:
// 发送短信验证码
@RequestMapping(value = {"/sendSmsVerificationCode/{phoneNumber}", "/sendSmsVerificationCode/{phoneNumber}/{phoneAreaCode}"}, method = RequestMethod.GET)
@ResponseBody
public int sendSmsVerificationCode(@PathVariable String phoneNumber, @PathVariable(required = false) String phoneAreaCode) {
if (TextUtil.isNullOrEmpty(phoneAreaCode)) phoneAreaCode = "86";
return WebClientUtil.getAsInt(String.format("/my/sendSmsVerificationCode2/%s/%s", phoneNumber, phoneAreaCode));
}
设置了phoneAreaCode参数非必须, @PathVariable(required = false) String phoneAreaCode