发表于: 2017-10-25 22:15:01
2 767
今天完成的事情:
1.完成了文件迁移
代码:
public static void AliToQiNiu() {
List<String> keys = ALiYunUtil.getAllFileName();
for (String key : keys) {
QiNiuUtil.upLoad(ALiYunUtil.downLoad(key), key);
}
}
public static void QiNiuToALi() {
List<String> keys = QiNiuUtil.getAllFileName();
for (String key : keys) {
ALiYunUtil.upLoad(QiNiuUtil.downLoad(key), key);
}
}
测试类:
@Test
public void aliToQiNiu() throws Exception {
DataMigrationUtil.AliToQiNiu();
}
@Test
public void qiNiuToALi() throws Exception {
DataMigrationUtil.QiNiuToALi();
}
七牛云文件:
阿里云清空:
测试:七牛云——》阿里云
清空七牛云:
测试:阿里云——》七牛云
2.实现异步提交验证码,最后提交表单
还以为后面很简单了,就是写写页面嘛,还不知道自己陷入了一个大坑
刚开始十分愚蠢的想要使用两个表单,然而我发现这是不能完成的……
直到下午才醒悟,请教师兄,去百度“ajax”,emmm..........
然后看了一下午的JQ和ajax教程,下面是成果
<script src="${ctx}/static/jquery-3.2.1.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#btn").click(function () {
var obj = {};
obj['tel'] = $("#tel").val();
$.ajax({
type:"POST",
url:"sms/code",
dataType:"json",
contentType:"application/json",
data:JSON.stringify(obj),
success:function(result){
}
});
});
});
</script>
<form style="text-align:center;" action="${ctx}/sms/test" method="post">
<input name="username" type="text" placeholder="账户名" ><br><br>
<input name="password" type="password" placeholder="密码" ><br><br>
<input name="confirmPwd" type="password" placeholder="确认密码" ><br><br>
<input name="tel" id="tel" type="text" placeholder="手机号码" ><br><br>
<input name="userCode" type="password" placeholder="验证码"><br><br>
<%-- <input class="button" type="submit" value="发送验证码">--%>
<input id="btn" class="button" type="button" value="发送验证码">
<%--<button class="botton">发送验证码</button>--%>
<input class="button" type="submit" value="注册">
</form>
点击发送验证码可以成功调用下面的控制器
@RequestMapping(value = "/sms/code", method = RequestMethod.POST)
@ResponseBody
public void sendSMSTest(@RequestBody Map<String, String> map,HttpSession session) {
session.invalidate();
int intCode = (int)((Math.random() * 9 + 1) * 1000);
String code = String.valueOf(intCode);
String tel = map.get("tel");
SMSUtil.sendSMS(tel, code, "5");
/* session.setAttribute("code", code);*/
log.error("ResponseBody");
/* return code;*/
}
现在还存在两个问题没有解决,在下面说
明天计划的事情:
1.完成发送短信、邮件部分
2.完成上传图片页面
3.若还有时间,完成使用配置文件切换云存储
遇到的问题:
1.如何点击按钮,不触发表单提交
解决方法:form中input类型使用button,使用jq触发事件,使用ajax提交数据
2.使用session的setAttribute方法存入验证码,在提交表单时再getAttribute获取验证码和用户输入的验证码,但是注册老是失败,以为是session中的值不能覆盖,然后在/sms/code控制器中使用invalidate方法先清空session中数据,但是还是不行。后来直接在注册按钮触发的控制器中打了日志
@RequestMapping(value = "/sms/test", method = RequestMethod.POST)
public ModelAndView SMSRegisterTest( HttpServletRequest request,HttpSession session) {
ModelAndView mv = new ModelAndView();
User user = new User();
user.setUsername(request.getParameter("username"));
user.setPassword(request.getParameter("password"));
String confirmPwd = request.getParameter("confirmPwd");
String code = (String) session.getAttribute("code");
String userCode = request.getParameter("userCode");
log.error("code:" + code + ",userCode:" + userCode); 日志
if (confirmPwd.equals(user.getUsername()) && code.equals(userCode)) {
userService.insertUser(user);
mv.addObject("username", user.getUsername());
mv.setViewName("registerSuccess");
return mv;
}
mv.setViewName("registerFail");
return mv;
}
结果:
传不过来,不知道为什么,百度了也没法搞定,然后打算使用ajax获取/sms/code控制器返回的值,放到注册表单中提交
这个等明天再实现
收获:
通过ajax提交数据,学到了些许的jq知识,感觉有点空闲时间的话可以全部学完
进度:
任务7开始时间:2017.10.18
预计demo时间:2017.10.26
延期风险:有
理由:一脚踩进大坑,觉得要延期了……
禅道
http://task.ptteng.com/zentao/project-task-350.html
评论