Decoration7:注册登录设计
首先顶一个小目标:从前台写入用户数据后,登录的时候输入用户名和密码,能够查询数据库成功,同时记录session数据
1、Login界面,为了只关注主线任务,我直接套用一个bootstrap模板adminLTE(https://adminlte.io)
2、Regist分为ok和not ok两种结果,为了增加一点难度,我设置userName和pqssWord不能为空,这用到了Hibernate的注解功能
@Column(nullable=false,unique=true)
private String userName;
@Column(nullable=false)
private String passWord;
还有一个@NotNull的的注解,其区别从Internet上找到一段话:
@NotNull is a JSR 303 Bean Validation annotation. It has nothing to do with database constraints itself. As Hibernate is the reference implementation of JSR 303, however, it intelligently picks up on these constraints and translates them into database constraints for you, so you get two for the price of one. @Column(nullable = false) is the JPA way of declaring a column to be not-null. I.e. the former is intended for validation and the latter for indicating database schema details. You're just getting some extra (and welcome!) help from Hibernate on the validation annotations.
3、Regist的时候,用户首先就要明确自己以什么样的角色使用这个系统。所以我在注册的界面做了一个下拉列表,列表展示网站支持的角色,用ng-init="init()"方法进行初始化,这里在展示option列表的时候有一些坑,下面是我的写法:
<select class="form-control" ng-model="user.role" ng-options="role.name for role in roles">
<option value="" selected="selected">---Please Select---</option>
</select>
role.name作为标签,role对象整个作为value值,在controller里面提交给后台之前,需要从role对象中取出Id传递给后台
4、前面提到,Regist必须和角色相关联,在设计数据库的时候,user-->owner,user-->designer,这里设计的是继承关系,所以一旦角色确定了,我们就不能只创建user表的数据,不管owner表。我的做法是根据role识别出是哪个子类,直接用子对象提交,这样父表也会一起创建。
$scope.regist = function(user) {
commonService.setBaseUrl(user.role.name.toLowerCase());//son table name
commonService.create(user).then(function(data) {}, function() {})
};
5、Regist成功之后,再看看Login的实现,Spring JPA支持的查询的格式:
http://localhost:8080/user/search/findByUserNameAndPassWord?userName=Jack&passWord=123
我要构造出这样一个格式和参数结构,发送到后台请求去,后台其实不需要做什么,默认支持。
$scope.login = function(user) {
var keyMap = {userName:user.userName,passWord:user.passWord};//设置参数格式
var url = "user/search/findByUserNameAndPassWord";//设置url
commonService.search(url,keyMap).then(function(data) {
$localStorage.userInfo = data;//记录sessionStorage
}, function() {
$scope.errorMessage = 'Get OwnerList Error';
})
};
//查询对象
this.search = function(url,param){
return Restangular.all(url).getList(param);//RestAngular的参数格式
};
这个时候我们看一下后台的select语句是什么样的:
select user0_.id as id1_5_, user0_.age as age2_5_, user0_.email as email3_5_, user0_.log_date as log_date4_5_, user0_.pass_word as pass_wor5_5_, user0_.reg_date as reg_date6_5_, user0_.role_id as role_id7_5_, user0_.status as status8_5_, user0_.tel as tel9_5_, user0_.user_name as user_na10_5_, user0_2_.companid as companid1_1_, user0_4_.build_num as build_nu1_3_,
case
when user0_1_.id is not null then 1
when user0_2_.id is not null then 2
when user0_3_.id is not null then 3
when user0_4_.id is not null then 4
when user0_.id is not null then 0
end
as clazz_ from user user0_
left outer join admin user0_1_ on user0_.id=user0_1_.id
left outer join designer user0_2_ on user0_.id=user0_2_.id
left outer join labour user0_3_ on user0_.id=user0_3_.id
left outer join owner user0_4_ on user0_.id=user0_4_.id
where user0_.user_name='mingming' and user0_.pass_word = ''
从结果可以看出,这个查询查询出了所有的子类信息+父类信息
6、最后看看Session怎么存储和使用,我们使用一个ngStorage的插件
Decoration7:注册登录设计的更多相关文章
- 如何设计一个 App 的注册登录流程?
移 动设备发力之前的登录方式很简单:用户名/邮箱+密码+确认密码,所有的用户登录注册都是围绕着邮箱来做.随着移动设备和社交网络的普及,邮箱不再是唯 一,渐渐的出现了微博,QQ,微信等第三方登录方式,手 ...
- SpringBoot + Vue + ElementUI 实现后台管理系统模板 -- 后端篇(五): 数据表设计、使用 jwt、redis、sms 工具类完善注册登录逻辑
(1) 相关博文地址: SpringBoot + Vue + ElementUI 实现后台管理系统模板 -- 前端篇(一):搭建基本环境:https://www.cnblogs.com/l-y-h/p ...
- Node.js基于Express框架搭建一个简单的注册登录Web功能
这个小应用使用到了node.js bootstrap express 以及数据库的操作 :使用mongoose对象模型来操作 mongodb 如果没了解过的可以先去基本了解一下相关概念~ 首先注 ...
- JavaWeb笔记——注册登录系统项目思路
功能: > 注册 > 登录 --------------------------------- JSP: * login.jsp --> 登录表单 * regist ...
- 注册登录系统项目思路 -- javaweb
功能: > 注册 > 登录 --------------------------------- JSP: * login.jsp --> 登录表单 * re ...
- vue2.0+koa2+mongodb实现注册登录
前言 前段时间和公司一个由技术转产品的同事探讨他的职业道路,对我说了一句深以为然的话: "不要把自己禁锢在某一个领域,技术到产品的转变,首先就是思维上的转变.你一直做前端,数据的交互你只知道 ...
- SpringBoot注册登录(三):注册--验证账号密码是否符合格式及后台完成注册功能
SpringBoot注册登录(一):User表的设计点击打开链接SpringBoot注册登录(二):注册---验证码kaptcha的实现点击打开链接 SpringBoot注册登录(三):注册 ...
- express+vue+mongodb+session 实现注册登录
上个月写了一篇文章是 express+mongodb+vue 实现增删改查. 只是简单的实现了增删改查功能,那么今天是在那个基础之上做了扩展,首先实现的功能有如下: 1. 支持注册,登录功能,用户可以 ...
- 2.1博客系统 |基于form组件和Ajax实现注册登录
基于forms组件和Ajax实现注册功能 1 基于forms组件设计注册页面 --点击头像 === 点击input --头像预览: 修改用户选中的文件对象:获取文件对象的路径:修改img的src属性, ...
随机推荐
- Latex 语法总结——层次结构
层次结构~~documentclass[a4paper,11pt]{article}\usepackage{CJKutf8}\usepackage[top=1in, bottom=1in, left= ...
- Integer判断相等,到底该用==还是equals
在项目中涉及到整数判断的时候一直都是使用"=="进行判断的,但是用的时候心里老是在犯嘀咕,是不是应该使用equals呀?今天来看下这个问题! 在Object类中,equals方法的 ...
- 10723 Cyborg Genes (LCS + 记忆化搜索)
Problem F Cyborg Genes Time Limit 1 Second September 11, 2132. This is the day that marks the beginn ...
- [CF 295A]Grag and Array[差分数列]
题意: 有数列a[ ]; 操作op[ ] = { l, r, d }; 询问q[ ] = { x, y }; 操作表示对a的[ l, r ] 区间上每个数增加d; 询问表示执行[ x, y ]之间的o ...
- 将应用发布到WasLiberty的两种方法
1.直接将War放到defaultserver(或其它自定义server)的dropin目录. 一放进去,war中的app就会随着server启动起来,这个war是会被解压的,用find / -nam ...
- Qt 之 QtConcurrent
本文以 Qt 中的 QtConcurrent::run() 函数为例,介绍如何将函数运行在单独的某一个线程中. 1 QtConcurrent::run() QtConcurrent 是一个命名空间, ...
- python的加密模块(md5,sha,crypt)学习
python的加密模块(md5,sha,crypt)学习 命令行使用python MD5: yinguicai@Cpl-IBP-Product:~/data/work/svn/v1.4.0_dev/A ...
- synthesis-of-weak-property-only-allowed-in-arc-or-gc-mode ARC属性
synthesis-of-weak-property-only-allowed-in-arc-or-gc-mode ARC属性 错误提示: 1:确认你的项目是 ARC环境: 2:如果 ARC下出现上面 ...
- 扩展MSEG 加入Z字段
append MSEG append IMSEG append BAPI_TE_XMSEG 实现 BADI: MB_BAPI_GOODSMVT_CREATE BAPI中: BAPI_ ...
- 使用JNDI连接数据库
第一步:实现一个Java类: package com.logistic.data; import java.sql.*;import javax.sql.*;import javax.naming.* ...