注册数据库 使用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 字节操作

    获取byte的高4位bit和低4位bit function getHeight4(ata){//获取高四位 int height; height = ((data & 0xf0) >&g ...

  2. iOS pushViewController 和 presentViewController的区别 详解

    pushViewController 导航控制器入栈的方式切换页面presentViewController 模态切换的方式切换页面 1:用 UINavigationController 的时候用 p ...

  3. adb命令获取app布局文件xml

    adb shell /system/bin/uiautomator dump --compressed /data/local/tmp/uidump.xml adb pull /data/local/ ...

  4. Github的fork进行同步

    最近项目要求每个开发人员都有自己fork,需要在自己的fork下进行开发.这样就涉及的到fork和原仓库的同步问题. 在网上查找到fork和原仓库同步的方法,如下转载自网上查找的内容,使用终端命令行进 ...

  5. 208道Java常见的面试题

    一.Java 基础 1.JDK 和 JRE 有什么区别? JRE=JVM+各种基础类库+java类库(String\System) JDK>JRE>JVM JRE:是java运行时环境  ...

  6. Js网站开发学习第一天

    1.登录时,记住密码单选框,鼠标移上去显示div里的内容,移开则消失: <head> <meta http-equiv="Content-Type" conten ...

  7. javascript_17-基本类型和引用类型

    基本类型 直接存储值 Number . String .Boolean undefined.null 引用类型 存储引用 -Object.Array.Date.函数 包装基本类型--引用类型 func ...

  8. Flink源码阅读(一)——Flink on Yarn的Per-job模式源码简析

    一.前言 个人感觉学习Flink其实最不应该错过的博文是Flink社区的博文系列,里面的文章是不会让人失望的.强烈安利:https://ververica.cn/developers-resource ...

  9. 大数据技术之Hadoop3.1.2版本伪分布式部署

    大数据技术之Hadoop3.1.2版本伪分布式部署 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.主机环境准备 1>.操作系统环境 [root@node101.yinzh ...

  10. Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题

    Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题 [Problem Description] ​ 总共两次询 ...