首先顶一个小目标:从前台写入用户数据后,登录的时候输入用户名和密码,能够查询数据库成功,同时记录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. matlab中m文件与m函数的学习与理解

    1. m文件与m函数的区别 所谓 MATLAB 程序,大致分为两类: M 脚本文件 (M-Script) 和 M 函数 (M-function), 它们均是普通的 ASCII 码构成的文件. M 脚本 ...

  2. ICLR 2016 - Workshop Track International Conference on Learning Representations 论文papers

    ICLR 2016 - Workshop Track International Conference on Learning Representations May 2 - 4, 2016, Car ...

  3. Python学习(五)函数 —— 内置函数 lambda filter map reduce

    Python 内置函数 lambda.filter.map.reduce Python 内置了一些比较特殊且实用的函数,使用这些能使你的代码简洁而易读. 下面对 Python 的 lambda.fil ...

  4. 关于TagHelper的那些事情——自定义TagHelper(格式化输出、依赖注入使用)

    自定义TagHelper的最后一步就是在Process方法或ProcessAsync方法中添加展现代码.熟悉WebControl开发的朋友都知道Render方法,在这个方法中会添加展现的Html元素和 ...

  5. SQL Server会话KILL不掉,一直处于KILLED /ROLLBACK状态情形浅析[转]

    本文将为您描述SQL Server会话KILL不掉,一直处于KILLED /ROLLBACK状态情形浅析,教程操作方法: 今天遇到一个很奇怪的情况,发现一个会话异常,这个会话只是在执行一个简单的存储过 ...

  6. linux shell scripts:Syntax error: Bad for loop variable

    执行脚本报错 #!/bin/bash s=0 for (( i=1; i<=100; i++ )) do s=$(( $s + $i )) done echo $s sh add.sh 报错: ...

  7. log4j.properties 详解与配置步骤总结

    先提供一个项目中使用log4j.properties配置 #log4j.rootLogger=WARN, stdout, file log4j.rootLogger=INFO,console,dail ...

  8. (LeetCode 72)Edit Distance

    Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2 ...

  9. 谋哥:《App自推广》开篇之回到远古人类

    [谋哥每天一干货.第六十八篇] 这两天帮谋天团的杨整体验他的App--"闪聊"的内測新版,改版后这款App命名为"美丫",一款致力于打造国内首款专注于女性社交的 ...

  10. Scheme 4 Javaer-3.高阶函数

    1.3  Formulating Abstractions with Higher-Order Procedures 教材有时候依照学生的基础.从0讲起:有时候给出一个大图,然后具体地逐一介绍. 本文 ...