首先顶一个小目标:从前台写入用户数据后,登录的时候输入用户名和密码,能够查询数据库成功,同时记录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:注册登录设计的更多相关文章

  1. 如何设计一个 App 的注册登录流程?

    移 动设备发力之前的登录方式很简单:用户名/邮箱+密码+确认密码,所有的用户登录注册都是围绕着邮箱来做.随着移动设备和社交网络的普及,邮箱不再是唯 一,渐渐的出现了微博,QQ,微信等第三方登录方式,手 ...

  2. SpringBoot + Vue + ElementUI 实现后台管理系统模板 -- 后端篇(五): 数据表设计、使用 jwt、redis、sms 工具类完善注册登录逻辑

    (1) 相关博文地址: SpringBoot + Vue + ElementUI 实现后台管理系统模板 -- 前端篇(一):搭建基本环境:https://www.cnblogs.com/l-y-h/p ...

  3. Node.js基于Express框架搭建一个简单的注册登录Web功能

    这个小应用使用到了node.js  bootstrap  express  以及数据库的操作 :使用mongoose对象模型来操作 mongodb 如果没了解过的可以先去基本了解一下相关概念~ 首先注 ...

  4. JavaWeb笔记——注册登录系统项目思路

    功能:   > 注册   > 登录 --------------------------------- JSP:   * login.jsp  --> 登录表单   * regist ...

  5. 注册登录系统项目思路 -- javaweb

    功能:   > 注册   > 登录   ---------------------------------   JSP:   * login.jsp  --> 登录表单   * re ...

  6. vue2.0+koa2+mongodb实现注册登录

    前言 前段时间和公司一个由技术转产品的同事探讨他的职业道路,对我说了一句深以为然的话: "不要把自己禁锢在某一个领域,技术到产品的转变,首先就是思维上的转变.你一直做前端,数据的交互你只知道 ...

  7. SpringBoot注册登录(三):注册--验证账号密码是否符合格式及后台完成注册功能

    SpringBoot注册登录(一):User表的设计点击打开链接SpringBoot注册登录(二):注册---验证码kaptcha的实现点击打开链接      SpringBoot注册登录(三):注册 ...

  8. express+vue+mongodb+session 实现注册登录

    上个月写了一篇文章是 express+mongodb+vue 实现增删改查. 只是简单的实现了增删改查功能,那么今天是在那个基础之上做了扩展,首先实现的功能有如下: 1. 支持注册,登录功能,用户可以 ...

  9. 2.1博客系统 |基于form组件和Ajax实现注册登录

    基于forms组件和Ajax实现注册功能 1 基于forms组件设计注册页面 --点击头像 === 点击input --头像预览: 修改用户选中的文件对象:获取文件对象的路径:修改img的src属性, ...

随机推荐

  1. (转)找回vss超级管理员密码

    原文:http://www.cnblogs.com/446557021/archive/2011/01/05/1926213.html 如果忘记了VSS管理员密码,打开vss数据库所在的文件夹,打开d ...

  2. JavaScript 函数大全

    javascript函数一共可分为五类: ·常规函数 ·数组函数 ·日期函数 ·数学函数 ·字符串函数 1.常规函数 javascript常规函数包括以下9个函数: (1)alert函数:显示一个警告 ...

  3. iOS: 如何调节UITabbarItem的图片和文字位置

    转载自:http://blog.csdn.net/kevinwlc/article/details/21467499/ 在ios7中,方法setFinishedSelectedImage:withFi ...

  4. servlet中获得tomcat项目根目录的绝对路径

    public class CreateXmlAction extends HttpServlet { private ServletConfig config; public void init(Se ...

  5. CentOS7 rpm方式安装mysql5.7

    内容源自:CentOS7安装mysql 在CentOS中默认安装有MariaDB,这个是MySQL的分支,但为了需要,还是要在系统中安装MySQL,而且安装完成之后可以直接覆盖掉MariaDB. 1. ...

  6. sql server 批量导出存储过程

    sys.syscomments:包含数据库中每个视图.规则.默认值.触发器.CHECK 约束.DEFAULT 约束和存储过程的项.text 列包含原始的 SQL 定义语句.(简单点说,这个系统表存储了 ...

  7. 【JAVA】【NIO】10、Java NIO ServerSocketChannel

    Java NIO的ServerSocketChannel是用来监听外来TCP连接的channel,就想标准Java网络中的ServerSocket.实比例如以下: ServerSocketChanne ...

  8. discuz,ecshop的伪静态规则(apache+nginx)

    discuz(nginx): (备注:该规则也适用于二级目录) rewrite ^([^\.]*)/topic-(.+)\.html$ $/portal.php?mod=topic&topic ...

  9. Python 面向对象编程基础

    Python 面向对象编程基础 虽然Pthon是解释性语言,但是Pthon可以进行面向对象开发,小到 脚本程序,大到3D游戏,Python都可以做到. 一类: 语法: class 类名: 类属性,方法 ...

  10. 算法笔记_155:算法提高 概率计算(Java)

    目录 1 问题描述 2 解决方案   1 问题描述 问题描述 生成n个∈[a,b]的随机整数,输出它们的和为x的概率. 输入格式 一行输入四个整数依次为n,a,b,x,用空格分隔. 输出格式 输出一行 ...