SpringBoot简单登录注册-注册(附源码)

并非是那种传授并分享知识的,只想在个人博客上把自己学的东西记录下来,也希望我记录的东西对各位看官有帮助。


下面是大致的结构目录跟效果图

SpringBoot简单登录注册-注册(附源码)_第1张图片


SpringBoot简单登录注册-注册(附源码)_第2张图片


要解释起来一时半会说不清楚,干脆就直接偷懒上注册的代码跟源码

其实代码很少,也很容易理解

pro.xm

[java]  view plain  copy
 print ?
  1.   
  2.     org.springframework.boot  
  3.     spring-boot-starter-parent  
  4.     1.5.3.RELEASE  
  5.        
  6.     
  7.   
  8.     
  9.     UTF-8  
  10.     UTF-8  
  11.     1.8  
  12.     
  13.   
  14.     
  15.       
  16.       org.springframework.boot  
  17.       spring-boot-starter-web  
  18.       
  19.   
  20.       
  21.       org.springframework.boot  
  22.       spring-boot-starter-test  
  23.       test  
  24.       
  25.   
  26.       
  27.       
  28.       org.springframework.boot  
  29.       spring-boot-starter-data-jpa  
  30.       
  31.       
  32.       mysql  
  33.       mysql-connector-java  
  34.       
  35.   
  36.       
  37.       org.springframework.boot  
  38.       spring-boot-starter-thymeleaf  
  39.       
  40.   
  41.   
  42.       
  43.       
  44.       com.alibaba  
  45.       fastjson  
  46.       1.2.16  
  47.       
  48.   
  49.     
  50.   
  51.     
  52.     IDEAmaven  
  53.       
  54.         
  55.         org.springframework.boot  
  56.         spring-boot-maven-plugin  
  57.         
  58.       
  59.     
  60.   
  61.     
  62.       
  63.       spring-releases  
  64.       https://repo.spring.io/libs-release  
  65.       
  66.     
  67.     
  68.       
  69.       spring-releases  
  70.       https://repo.spring.io/libs-release  
  71.       
  72.     

UserEntity

[java]  view plain  copy
 print ?
  1. @Entity(name="table_user")  
  2. public class UserEntity {  
  3.   
  4.     @Id  
  5.     @GeneratedValue  
  6.     private Long id;  
  7.     private String username;  
  8.     private String password;  
  9.   
  10.     public Long getId() {  
  11.         return id;  
  12.     }  
  13.   
  14.     public void setId(Long id) {  
  15.         this.id = id;  
  16.     }  
  17.   
  18.     public String getUsername() {  
  19.         return username;  
  20.     }  
  21.   
  22.     public void setUsername(String username) {  
  23.         this.username = username;  
  24.     }  
  25.   
  26.     public String getPassword() {  
  27.         return password;  
  28.     }  
  29.   
  30.     public void setPassword(String password) {  
  31.         this.password = password;  
  32.     }  
  33. }  

index.html和register.html

[java]  view plain  copy
 print ?
  1.   
  2.     "UTF-8" />  
  3.     Title  
  4.   
  5.   
  6.   
  7. 注册成功后的跳转页面  
  8.   
  9.   

[java]  view plain  copy
 print ?
  1.   
  2.     "UTF-8" />  
  3.     Title  
  4.   
  5.   
  6. class="web_login">  
  7.     "form2" id="regUser" accept-charset="utf-8"  action="/front/addregister" method="post">  
  8.         class="reg_form" id="reg-ul">  
  9.             "userCue" class="cue">快速注册请注意格式
  
  •             
  •   
  •                 for="username"  class="input-tips2">用户名:  
  •                 class="inputOuter2">  
  •                     "text" id="username" name="username" maxlength="16" class="inputstyle2"/>  
  •                 
  •   
  •             
  •   
  •             
  •   
  •                 for="password" class="input-tips2">密码:  
  •                 class="inputOuter2">  
  •                     "password" id="password"  name="password" maxlength="16" class="inputstyle2"/>  
  •                 
  •   
  •             
  •   
  •             
  •   
  •                 for="password2" class="input-tips2">确认密码:  
  •                 class="inputOuter2">  
  •                     "password" id="password2" name="password2" maxlength="16" class="inputstyle2" />  
  •                 
  •   
  •             
  •   
  •             
  •   
  •                 class="inputArea">  
  •                     "submit" id="reg"  style="margin-top:10px;margin-left:85px;" class="button_blue" value="同意协议并注册"/> "#" class="zcxy" target="_blank">注册协议  
  •                 
  •   
  •             
  • class="cl">
      
  •           
  •       
  •   
  •   
  • UserDao和IndexController

    [java]  view plain  copy
     print ?
    1. @Repository  
    2. public interface UserDao extends CrudRepository{  
    3.   
    4.     public UserEntity findByUsernameAndPassword(String username,String password);  
    5.   
    6. }  

    [java]  view plain  copy
     print ?
    1. @Controller  
    2. @RequestMapping("/front/*")  
    3. public class IndexController {  
    4.   
    5.     @Autowired  
    6.     private UserDao userDao;  
    7.   
    8.     //index页面  
    9.     @RequestMapping("/index")  
    10.     public String index() {  
    11.         return "index";  
    12.     }  
    13.   
    14.     //登录页面  
    15.     @RequestMapping("/register")  
    16.     public String register(){  
    17.         return "register";  
    18.     }  
    19.   
    20.     //注册方法  
    21.     @RequestMapping("/addregister")  
    22.     public String register(HttpServletRequest request){  
    23.         String username = request.getParameter("username");  
    24.         String password = request.getParameter("password");  
    25.         String password2 = request.getParameter("password2");  
    26.         if (password.equals(password2)){  
    27.             UserEntity userEntity = new UserEntity();  
    28.             userEntity.setUsername(username);  
    29.             userEntity.setPassword(password);  
    30.             userDao.save(userEntity);  
    31.             return "index";  
    32.         }else {  
    33.             return "register";  
    34.         }  
    35.     }  
    36.   
    37. }  



    源码下载

    插眼传送

    你可能感兴趣的:(Mysql)