SpringMVC中 @RequestMapping配置多个路径 @PathVariable设置为空(required = false)

在实现发送短信验证码功能的时候, @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

你可能感兴趣的:(Java)