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. Linux系统学习之Linux账号管理

    一.基本介绍 Linux用户分为三类,即普通用户.根用户.系统用户. 普通用户指的是所有使用Linux系统的真实用户. 根用户就是root用户,权限最大,它的ID为0,也被称为超级用户,root用户拥 ...

  2. windows系统VS2017编译boost

    1. 下载boost, 解压,进入boost源目录 2. 打开vs2017 x86 CMD工具,输入bootstrap.bat,等待初始化完毕 x86编译 bjam stage --toolset=m ...

  3. vue-cli sass安装

    一.安装对应依赖node模块: npm install node-sass --save-dev npm install sass-loader --save-dev 二.打开webpack.base ...

  4. django 接受 ajax 传来的数组对象

    django 接受 ajax 传来的数组对象 发送:ajax 通过 POST 方式传来一个数组 接收:django 接受方式 array = request.POST.getlist(‘key[]’) ...

  5. 在Winform框架界面中改变并存储界面皮肤样式

    在本篇介绍的Winform界面样式改变及存储操作中,是指基于DevExpress进行界面样式的变化.一般情况下,默认我们会为客户提供多种DevExpress的界面皮肤以供个人喜好选择,默认DevExp ...

  6. DOM(二)

    文档信息 document对象还有一些标准的Document对象所没有的属性: title属性:包含着<title>元素中的文本——显示在浏览器窗口的标题栏或标签页上,通过整个属性可以取得 ...

  7. Nginx监控运维

    Nginx是一个开源.免费.高性能的HTTP和反向代理服务器,也可以用于IMAP/POP3代理服务器.充分利用Nginx的特性,可以有效解决流量高并发请求.cc攻击等问题. 本文探讨了电商场景下Ngi ...

  8. Python-0010-

    题目: 判断101-200之间有多少素数,并输出所有素数. 程序分析: 判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除则表明次数不是素数,反之是素数.用else 可以进一步简化代 ...

  9. Django 2.0 学习

    Django django是基于MTV结构的WEB框架 Model 数据库操作 Template 模版文件 View 业务处理 在Python中安装django 2.0 1 直接安装 pip inst ...

  10. Nagios 系统监控

    Nagios 系统监控 Nagios 是一款免费的开源 IT 基础设施监控系统,功能强大,灵活性强,能有效监控 Windows.Linux.VMware 和 Unix 主机状态,交换机.路由器等网络设 ...