SpringBoot构建电商基础秒杀项目 学习笔记

userDOMapper.xml 添加

  <select id="selectByTelphone" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from user_info
where telphone = #{telphone,jdbcType=VARCHAR}
</select>

userDOMapper 添加

    UserDO selectByTelphone(String telphone);

UserService 添加

    UserModel validateLogin(String telphone, String encrptPassword) throws BusinessException;

UserServiceImpl 添加

    @Override
public UserModel validateLogin(String telphone, String encrptPassword) throws BusinessException { UserDO userDO = userDOMapper.selectByTelphone(telphone); if(userDO == null){
throw new BusinessException(EmBusinessError.USER_LOGIN_FAIL);
} UserPasswordDO userPasswordDO = userPasswordDOMapper.selectByUserId(userDO.getId()); UserModel userModel = convertFromDataObject(userDO, userPasswordDO); if(!StringUtils.equals(encrptPassword, userModel.getEncrptPassword())){
throw new BusinessException(EmBusinessError.USER_LOGIN_FAIL);
} return userModel;
}

UserController 添加

    @RequestMapping(value = "/login", method = {RequestMethod.POST}, consumes = {CONTENT_TYPE_FORMED})
@ResponseBody
public CommonReturnType login(@RequestParam(name="telphone") String telphone,
@RequestParam(name="password") String password)
throws BusinessException, UnsupportedEncodingException, NoSuchAlgorithmException { if(StringUtils.isEmpty(telphone) || StringUtils.isEmpty(password)){
throw new BusinessException(EmBusinessError.PARAMETER_VALIDATION_ERROR);
} UserModel userModel = userService.validateLogin(telphone, EncodeByMd5(password)); httpServletRequest.getSession().setAttribute("LOGIN", true);
httpServletRequest.getSession().setAttribute("LOGIN_USER", userModel); return CommonReturnType.create(null);
}

新建 login.html

<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
</head> <body>
<div id="app">
<el-row>
<el-col :span="8" :offset="8">
<h3>用户登陆</h3>
<el-form ref="form" :model="form" label-width="80px">
<el-form-item label="手机号">
<el-input v-model="form.telphone"></el-input>
</el-form-item>
<el-form-item label="密码">
<el-input v-model="form.password" show-password></el-input>
</el-form-item> <el-form-item>
<el-button type="primary" @click="onSubmit">登陆</el-button>
<el-button @click="register">注册</el-button>
</el-form-item>
</el-form>
</el-col>
</el-row>
</div>
</body> <script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="https://cdn.bootcss.com/axios/0.18.0/axios.min.js"></script>
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script>
var app = new Vue({
el: '#app',
data: {
form: {
telphone: '',
password: '',
}
},
methods: {
onSubmit(){ if(this.form.telphone == null || this.form.telphone == ''){
this.$message({
message: '手机号不能为空',
type: 'warning'
});
return;
} // https://www.cnblogs.com/yesyes/p/8432101.html
axios({
method: 'post',
url: 'http://localhost:8080/user/login',
data: this.form,
params: this.form,
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
withCredentials: true,
})
.then(resp=>{
if(resp.data.status == 'success'){
this.$message({
message: '登陆成功',
type: 'success'
});
}else{
this.$message.error('登陆失败,原因为:' + resp.data.data.errMsg);
}
})
.catch(err =>{
this.$message.error('登陆失败,原因为:' + err.status + ', ' + err.statusText);
});
}, register(){
window.location.href='getotp.html';
}, }, });
</script> </html>

源码:spring-boot-seckill

Spring Boot 构建电商基础秒杀项目 (六) 用户登陆的更多相关文章

  1. Spring Boot 构建电商基础秒杀项目 (一) 项目搭建

    SpringBoot构建电商基础秒杀项目 学习笔记 Spring Boot 其实不是什么新的框架,它默认配置了很多框架的使用方式,就像 maven 整合了所有的 jar 包, Spring Boot ...

  2. Spring Boot 构建电商基础秒杀项目 (十二) 总结 (完结)

    SpringBoot构建电商基础秒杀项目 学习笔记 系统架构 存在问题 如何发现容量问题 如何使得系统水平扩展 查询效率低下 活动开始前页面被疯狂刷新 库存行锁问题 下单操作步骤多,缓慢 浪涌流量如何 ...

  3. Spring Boot 构建电商基础秒杀项目 (十一) 秒杀

    SpringBoot构建电商基础秒杀项目 学习笔记 新建表 create table if not exists promo ( id int not null auto_increment, pro ...

  4. Spring Boot 构建电商基础秒杀项目 (十) 交易下单

    SpringBoot构建电商基础秒杀项目 学习笔记 新建表 create table if not exists order_info ( id varchar(32) not null defaul ...

  5. Spring Boot 构建电商基础秒杀项目 (九) 商品列表 & 详情

    SpringBoot构建电商基础秒杀项目 学习笔记 ItemDOMapper.xml 添加 <select id="listItem" resultMap="Bas ...

  6. Spring Boot 构建电商基础秒杀项目 (八) 商品创建

    SpringBoot构建电商基础秒杀项目 学习笔记 新建数据表 create table if not exists item ( id int not null auto_increment, ti ...

  7. Spring Boot 构建电商基础秒杀项目 (七) 自动校验

    SpringBoot构建电商基础秒杀项目 学习笔记 修改 UserModel 添加注解 public class UserModel { private Integer id; @NotBlank(m ...

  8. Spring Boot 构建电商基础秒杀项目 (五) 用户注册

    SpringBoot构建电商基础秒杀项目 学习笔记 UserService 添加 void register(UserModel userModel) throws BusinessException ...

  9. Spring Boot 构建电商基础秒杀项目 (四) getotp 页面

    SpringBoot构建电商基础秒杀项目 学习笔记 BaseController 添加 public static final String CONTENT_TYPE_FORMED = "a ...

随机推荐

  1. 深入理解 Servelt

    1.什么是 Servlet ? Servlet(Server Applet)是 Java Servlet 的简称,称为小服务程序或服务连接器,用 Java 编写的服务器端程序,具有独立于平台和协议的特 ...

  2. 解决IsEditable="True"的ComboBox在DataGrid中点击一次不能选中行的问题

    原文:解决IsEditable="True"的ComboBox在DataGrid中点击一次不能选中行的问题 此方法很笨拙,并不推荐使用!!! 此方法很笨拙,并不推荐使用!!! 此方 ...

  3. 腾讯首批 5000 人群,现在加入【FineUI总群】,极速体验!

    腾讯首批 5000 人群,稀缺资源,绝无仅有,快来体验! 加群链接:http://shang.qq.com/wpa/qunwpa?idkey=e81f012f9920c25a77c4fd8b0c767 ...

  4. 读写分离子系统 - C# SQL分发子系统 - Entity Framework支持

    A2D Framework增加了EF支持,加上原先支持ADO.NET: 支持EF方式 支持ADO.NET方式 这次来讲如何让Entity Framework变成nb的读写分离 1. 先设计EF模型, ...

  5. 一起学习造轮子(一):从零开始写一个符合Promises/A+规范的promise

    本文是一起学习造轮子系列的第一篇,本篇我们将从零开始写一个符合Promises/A+规范的promise,本系列文章将会选取一些前端比较经典的轮子进行源码分析,并且从零开始逐步实现,本系列将会学习Pr ...

  6. Java面试MySQL的一些问题

    MySQL InnoDB存储的文件结构 索引树是如何维护的? 数据库自增主键可能的问题

  7. Node+GitLab实现小程序CI系统

    为什么要实现自动部署 小程序开发迭代里,有以下几个个头痛的问题, 如何准确并快速的的把小程序上传去后台,并让测试人员进行测试? 测试同事找开发要二维码,效率较低 本地生成的二维码会出现携带本地代码.未 ...

  8. 不容错过的超赞项目管理PPT

    不容错过的超赞项目管理PPT(转载) 大公司的一个好处,是各个领域都有牛人,可以为你提供经验分享交流.腾讯庞大的培训体系更是保证了:如果你想学点什么东西,你总可以学到.腾讯内部资源30页PPT曝光 — ...

  9. socketserver + ftp

    --------------------------------------------生活不止眼前的苟且,还有诗和远方的田野. day 29 socketserver + ftp # # ----- ...

  10. vue 饿了么项目笔记

    vue 饿了么项目 1.图标字体引用 链接 2.scss 二三倍图切换 1像素边框 链接 3.better-scroll 4.布局 商品主页面 <div id="app"&g ...