您的位置:首页 > 编程语言 > Java开发

基于Spring Boot和Spring Cloud实现微服务架构学习

2017-03-24 16:38 1141 查看
@Api:用在类上,说明该类的作用
@ApiOperation:用在方法上,说明方法的作用
@ApiImplicitParams:用在方法上包含一组参数说明
@ApiImplicitParam:用在@ApiImplicitParams注解中,指定一个请求参数的各个方面
paramType:参数放在哪个地方
header-->请求参数的获取:@RequestHeader
query-->请求参数的获取:@RequestParam
path(用于restful接口)-->请求参数的获取:@PathVariable
body(不常用)
form(不常用)

name:参数名
dataType:参数类型
required:参数是否必须传
value:参数的意思
defaultValue:参数的默认值

@ApiResponses:用于表示一组响应
@ApiResponse:用在@ApiResponses中,一般用于表达一个错误的响应信息
code:数字,例如400
message:信息,例如"请求参数没填好"
response:抛出异常的类

@ApiModel:描述一个Model的信息(这种一般用在post创建的时候,使用@RequestBody这样的场景,请求参数无法使用@ApiImplicitParam注解进行描述的时候)

@ApiModelProperty:描述一个model的属性

@Autowired
StringRedisTemplate stringRedisTemplate;

@Autowired
SuggestService suggestService;

@Value("#{'${spring.http.multipart.location}'.endsWith('/')?'${spring.http.multipart.location}':'${spring.http.multipart.location}'+'/'}")
String location;

@ApiOperation(value="发送短信", notes="",response= JsonResult.class)
@ApiImplicitParams({
@ApiImplicitParam(name = "role", value = "0表示普通用户,1表示物业", required = true, dataType = "int",paramType = "query"),
@ApiImplicitParam(name = "phone", value = "手机号码", required = true, dataType = "string",paramType = "query"),
@ApiImplicitParam(name = "type", value = "0 表示注册,1.表示找密码", required = true, dataType = "int",paramType = "query")
})
@RequestMapping(value = "sendSMS")
public JsonResult sendSMS(int role,String phone, int type) {

//获取key,放入redis中 缓存10分钟
String key = String.format(RedisKey.USER_PHONE_ROLE_TYPE, phone,role,type);
String code = stringRedisTemplate.opsForValue().get(key);

if (StringUtils.isBlank(code)) {
code = String.valueOf(RandomUtil.random(4));
stringRedisTemplate.opsForValue().set(key, code);
stringRedisTemplate.expire(key, 10, TimeUnit.MINUTES);
}

String content = "您好,当前验证码为" + code + ",请勿泄露给他人";
//发送短信
boolean flag = SMSUtil.sendSMS(phone, content);
if (flag == true) {
return new JsonResult(ResultCode.SUCCESS);
} else {
return new JsonResult(ResultCode.COMMON_ERROR_SEND_SMS);
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐