注册数据库 使用spring boot 之登录笔记  的数据库

在server 层

User create(String username, String password, String email);
去serverimpl 实现
@Override
@Transactional
public User create(String username, String password, String email) {
User user = userRepository.findByUsername(username);
if (user == null) {
User newuser = new User();
newuser.setUsername(username);
newuser.setEmail(email);
String md5password;
String tokenmd5;
try {
md5password = MD5Until.md5(password);
tokenmd5 = MD5Until.md5(username + password);
} catch (Exception e) {
md5password = password;
tokenmd5 = username;
}
newuser.setPassword(md5password);
newuser.setToken(tokenmd5);
userRepository.save(newuser);
redisTemplate.delete("Plan_user");
return newuser;
}
throw new PanExection(ResultEmus.USER_EXIT);
}

  去开发对于的controller层

@GetMapping("/reg")
public ModelAndView reg(ModelAndView model) {
return new ModelAndView("register");
}
@PostMapping("/reg")
public ModelAndView regs(ModelAndView model, @Valid UserForm userVo, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
model.addObject("error", bindingResult.getFieldError().getDefaultMessage());
model.setViewName("register");
return model;
}
try {
User user = userSerice.create(userVo.getUsername(), userVo.getPassword(), userVo.getEmail());
return new ModelAndView("redirect:/plan/logins");
} catch (PanExection e) {
model.addObject("error", e.getMessage());
model.setViewName("register");
return model;
} }
PanExection.java
@Getter
public class PanExection extends RuntimeException {
private Integer code; public PanExection(ResultEmus resultEmuns) {
super(resultEmuns.getMessage());
this.code = resultEmuns.getCode();
} public PanExection(CaseResultEmus resultEmuns) {
super(resultEmuns.getMessage());
this.code = resultEmuns.getCode();
} public PanExection(Integer code, String message) {
super(message);
this.code = code;
}
}

  userForm

@Data
public class UserForm {
@NotEmpty(message = "用户名不能为空")
private String username;
@NotEmpty(message = "密码不能为空")
private String password;
@Email(message = "邮箱格式错误")
private String email;
}

开发对应的register.html代码

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"> <head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>AutoTestPlatform</title>
<!-- plugins:css -->
<link rel="stylesheet" href="../../node_modules/mdi/css/materialdesignicons.min.css">
<!-- endinject -->
<!-- plugin css for this page -->
<!-- End plugin css for this page -->
<!-- inject:css -->
<link rel="stylesheet" href="../../css/style.css">
<!-- endinject -->
</head> <body>
<div class="body-wrapper">
<div class="page-wrapper">
<main class="content-wrapper auth-screen">
<div class="mdc-layout-grid">
<div class="mdc-layout-grid__inner">
<div class="mdc-layout-grid__cell stretch-card mdc-layout-grid__cell--span-4">
</div>
<div class="mdc-layout-grid__cell stretch-card mdc-layout-grid__cell--span-4">
<div class="mdc-card">
<section class="mdc-card__primary bg-white">
<form th:action="@{/reg}" method="post">
<div>
<!--/*@thymesVar id="error" type=""*/-->
<span id="basic-addon0">&nbsp;</span>
<span style="font-size: 12px;color: red" th:text="${error}" aria-describedby="basic-addon0"></span>
<br />
</div>
<div class="mdc-layout-grid">
<div class="mdc-layout-grid__inner"> <div class="mdc-layout-grid__cell stretch-card mdc-layout-grid__cell--span-12">
<label class="mdc-text-field w-100">
<input type="text" class="mdc-text-field__input" name="username">
<span class="mdc-text-field__label">用户名</span>
<div class="mdc-text-field__bottom-line"></div>
</label>
</div>
<div class="mdc-layout-grid__cell stretch-card mdc-layout-grid__cell--span-12">
<label class="mdc-text-field w-100">
<input type="password" class="mdc-text-field__input" name="password">
<span class="mdc-text-field__label">密码</span>
<div class="mdc-text-field__bottom-line"></div>
</label>
</div>
<div class="mdc-layout-grid__cell stretch-card mdc-layout-grid__cell--span-12">
<label class="mdc-text-field w-100">邮箱
<input type="text" class="mdc-text-field__input" name="email">
<div class="mdc-text-field__bottom-line"></div>
</label>
</div> <div class="mdc-layout-grid__cell stretch-card mdc-layout-grid__cell--span-12">
<button class="mdc-button mdc-button--raised w-100" data-mdc-auto-init="MDCRipple">
注册
</button>
</div>
</div>
</div>
</form>
</section>
</div>
</div>
<div class="mdc-layout-grid__cell stretch-card mdc-layout-grid__cell--span-4">
</div>
</div>
</div>
</main>
</div>
</div>
<!-- body wrapper -->
<!-- plugins:js -->
<script src="../../node_modules/material-components-web/dist/material-components-web.min.js"></script>
<script src="../../node_modules/jquery/dist/jquery.min.js"></script>
<!-- endinject -->
<!-- Plugin js for this page-->
<!-- End plugin js for this page-->
<!-- inject:js -->
<script src="../../js/misc.js"></script>
<script src="../../js/material.js"></script>
<!-- endinject -->
<!-- Custom js for this page-->
<!-- End custom js for this page-->
</body> </html>

这也我们的关于注册界面代码书写完毕,启动调试

验证:

到此我们的注册界面开发完毕

spring boot 之注册的更多相关文章

  1. Spring boot 梳理 - Spring boot自动注册DispatcherServlet

    spring boot提供的DispatcherServlet的name就是“dispatcherServlet”. 源码 public ServletRegistrationBean dispatc ...

  2. Spring boot中注册Servlet

    Spring boot中注册Servlet 如何在spring boot项目中注册Servlet呢? 如何在spring boot项目中注册Servlet呢? 由于没有web.xml,无法直接在xml ...

  3. .net core + eureka + spring boot 服务注册与调用

    .net core + eureka + spring boot 服务注册与简单的调用 假期小长假遇上疫情只能去家里蹲了,刚好有时间总结一下. 概述 微服务架构是当前比较火的分布式架构,本篇基于.ne ...

  4. spring boot 登录注册 demo (四) -- 体验小结

    之前没有折腾过Spring,直接上来怼Spring Boot异常痛苦,参考着官网的guide(https://spring.io/guides)写了几个demo: spring boot 跑起来确是方 ...

  5. spring boot 登录注册 demo (二) -- 数据库访问

    通过data-jpa来访问数据库 <dependency> <groupId>org.springframework.boot</groupId> <arti ...

  6. Spring Boot 自定义注册 Servlet、Filter、Listener

    前言 在 Spring Boot 中已经移除了 web.xml 文件,如果需要注册添加 Servlet.Filter.Listener 为 Spring Bean,在 Spring Boot 中有两种 ...

  7. spring boot中注册拦截器

    拦截器是动态拦截Action调用的对象.它提供了一种机制可以使开发者可以定义在一个action执行的前后执行的代码,也可以在一个action执行前阻止其执行,同时也提供了一种可以提取action中可重 ...

  8. Spring Boot之注册servlet三大组件

    由于Spring Boot默认是以jar包的形式启动嵌入式的Servlet容器来启动Spring Boot的web应用是,没有web.xml配置文件 注册三大组件用以下方式 ServletRegist ...

  9. spring boot 登录注册 demo (一)

    Welcome to Spring Boot 代码结构 src/main/java 下 controller层,路由功能dao层,数据库的访问domain,bean的存放service,业务层appl ...

随机推荐

  1. js中this指向的三种情况

    js中this指向的几种情况一.全局作用域或者普通函数自执行中this指向全局对象window,普通函数的自执行会进行预编译,然后预编译this的指向是window //全局作用域 console.l ...

  2. Oracle - 实现MySQL的limit功能

    MySQL的limit功能是获取指定行数的数据,Oracle没有这个limit,但是有其它方法. oracle数据库不支持mysql中limit功能,但可以通过rownum来限制返回的结果集的行数,r ...

  3. BBPlus团队ALPFA冲刺(肖文恒)

    ALPHA冲刺博客 第一天:https://www.cnblogs.com/bbplus/p/11931039.html 第二天:https://www.cnblogs.com/bbplus/p/11 ...

  4. 美化shell

    Linux终端提示符颜色美化: (一)大致步骤:vim ~/.bashrc中设置PS1的值.保存后执行生效:source ~/.bashrc (二)PS1的值推荐:推荐1多色显示:用户白色:全路径(\ ...

  5. Host is not allowed to connect to this MySQL server

    解决方法: [root@GYQ-Prod-Zabbix ~]# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Com ...

  6. c# DirectoryInfo类

  7. 文件操作之stat()函数

    作用: 返回一个文件的详细信息 头文件: #include <sys/types.h> #include <sys/stat.h> #include <unistd.h& ...

  8. typescript 模块

    模块:模块可以帮助开发者将代码分割为重用的单元.开发者可以自己决定将模块中的哪些资源(类,方法,变量)暴露出去供外部使用,哪些资源只在模块内使用 在ts里面,一个文件就是一个模块,并没有什么特殊的标识 ...

  9. PAT1016 × PAT1017

    本次题解是综合1016和1017两道题来讲解,原因无他,因为这两道都是模拟题,综合字符串处理.排序等考点 接手一道模拟题,一定要快速且准确地了解模拟的过程,清晰题目涉及的关键信息.比如1016要计算电 ...

  10. LFU(最近最不常用)实现(python)

    from collections import defaultdict, OrderedDict class Node: __slots__ = 'key', 'val', 'cnt' def __i ...