发表于: 2017-12-03 23:24:21
0 701
今天完成的事情:本地打包到私服失敗 不知道咋回事 不用荣联了 改用阿里
阿里打包倒是没问题 测试类也跑通了 接口跑不通
@RequestMapping(value = "/a/sms", method = RequestMethod.POST)
public String getAuthCode(HttpServletRequest request, HttpServletResponse response,
ModelMap model,String mobile)
throws ServiceException, ServiceDaoException {
if (StringUtil.isEmpty(mobile)) {
log.info("Mobile is empty, please check the mobile.");
model.addAttribute("code", -1000);
return "/data/json";
}
log.info("Prepare to send authcode sms to mobile=" + mobile);
try {
Long uid = userService.getUserIdByMobile(mobile);
if (null != uid) {
log.info("Mobile=" + mobile + "has already register.");
model.addAttribute("code", -5019);//该用户已注册
return "/data/json";
}
String authCode = aliSMSUtil.getAuthCode();
boolean isOk = aliSMSUtil.sendAuthCode(mobile,authCode);
//若短信发送失败执行:
if (!isOk) {
model.addAttribute("code", -5022);//短信发送失败,请输入正确的手机号
log.info("Send authcode to mobile = " + mobile + " failure.");
return "/data/json";
}
log.info("Set session attribute which called " + mobile + "authCode.");
HttpSession session = request.getSession();
session.setAttribute(mobile + "authCode", authCode);
session.setMaxInactiveInterval(60 * 10);//有效时间10分钟
log.info("Send authcode=" + authCode + " to mobile=" + mobile);
model.addAttribute("code", 0);
}catch (Throwable t){
t.printStackTrace();
log.error(t.getMessage());
log.error("Get authcode sms failure because of server false.");
model.addAttribute("code",-1);
}
return "/data/json";
}
明天计划的事情:修改接口
遇到的问题:来回的用maven命令打包 clean install 或者打包到本地
mvn install:install-file -Dfile=E:\jbao\java_memcached-release_2.6.6.jar -DgroupId=com.danga -DartifactId=memcached -Dversion=2.6.6 -Dpackaging=jar -DgeneratePom=true
想简单点在lib里面直接添加 就是报错
收获:
handler method 参数绑定常用的注解,我们根据他们处理的Request的不同内容部分分为四类:(主要讲解常用类型)
A、处理requet uri 部分(这里指uri template中variable,不含queryString部分)的注解: @PathVariable;
B、处理request header部分的注解: @RequestHeader, @CookieValue;
C、处理request body部分的注解:@RequestParam, @RequestBody;
D、处理attribute类型是注解: @SessionAttributes, @ModelAttribute;
@PathVariable
当使用@RequestMapping URI template 样式映射时, 即 someUrl/{paramId}, 这时的paramId可通过 @Pathvariable注解绑定它传过来的值到方法的参数上。
@Controller
@RequestMapping("/owners/{ownerId}")
public class RelativePathUriTemplateController {
@RequestMapping("/pets/{petId}")
public void findPet(@PathVariable String ownerId, @PathVariable String petId, Model model) {
// implementation omitted }}
上面代码把URI template 中变量 ownerId的值和petId的值,绑定到方法的参数上。若方法参数名称和需要绑定的uri template中变量名称不一致,需要在@PathVariable("name")指定uri template中的名称。
@RequestHeader 注解,可以把Request请求header部分的值绑定到方法的参数上。
@RequestParam
A) 常用来处理简单类型的绑定,通过Request.getParameter() 获取的String可直接转换为简单类型的情况( String--> 简单类型的转换操作由ConversionService配置的转换器来完成);因为使用request.getParameter()方式获取参数,所以可以处理get 方式中queryString的值,也可以处理post方式中 body data的值;
B)用来处理Content-Type: 为 application/x-www-form-urlencoded编码的内容,提交方式GET、POST;
C) 该注解有两个属性: value、required; value用来指定要传入值的id名称,required用来指示参数是否必须绑定;
评论