SpringBoot+Vue+Element-ui实现简单登录注册功能

news2024/11/15 21:27:27

目录

1.前端

(1)登录和注册页面

   HomeView.vue   

   RegisterView.vue

(2) main.js,作请求和响应拦截

2.后端

(1)mapper.xml

(2)mapper接口

(3)Service接口

(4)Service实现类

(5)Controller控制器

(6)实体类

3.效果

1.前端

(1)登录和注册页面

   HomeView.vue   

<template>
  <div class="login-wrap">
      <el-form ref="form" :model="form">
        <h1 class="title">登录</h1>
        <el-form-item >
          <el-input type="text" v-model="form.username"  placeholder="用户账号" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item >
          <el-input type="password" v-model="form.password" placeholder="用户密码" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="doLogin" style="width: 100%;">登陆</el-button>
        </el-form-item>
        <el-row style="text-align: center;margin-top: -10px;">
            <el-link type="primary" @click="doRegister">注册账号</el-link> | 
            <el-link type="primary" @click="">忘记密码</el-link>
        </el-row>
      </el-form>
  </div>
</template>
<script>
  import axios from 'axios'
  export default{
   
     data(){
       return{
         form:{
           username:'',
           password:''
         }
       }
     },

     methods:{
       doLogin(){
         axios.post('http://localhost:8081/login',this.form).then(res=>{
           if(res.status==200){
             this.$message({
               message: '登陆成功',
               type: 'success'
             });
             this.$router.push('/person');
           }else{
             this.$message({
               message: '登陆失败',
               type: 'error'
             });
           }
         })
       },
       doRegister(){
         this.$router.push('/register');
       }
     }



  }
</script>
 
<style>
  	.login-wrap {
  		box-sizing: border-box;
  		width: 100%;
  		height: 100%;
  		padding-top: 10%;
  		bacJvdXAgMjE8L3RpdGxlPgogICAgPGRlc2M+Q3JlYXRlZCB3aXRoIFNrZXRjaC48L2Rlc2M+CiAgICA8ZGVmcz48L2RlZnM+CiAgICA8ZyBpZD0iQW50LURlc2lnbi1Qcm8tMy4wIiBzdHJva2U9Im5vbmUiIHN0cm9rZS13aWR0aD0iMSIgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIj4KICAgICAgICA8Zy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AgPGNpcmNsZSBpZD0iT3ZhbC01LUNvcHktMiIgZmlsbC1vcGFjaXR5PSIwLjYiIGZpbGw9IiNEMURFRUQiIGN4PSI4Ljc1IiBjeT0iMzMuMjUiIHI9IjguNzUiPjwvY2lyY2xlPgogICAgICAgICAgICAgICAgICAgIDxjaXJjbGUgaWQ9Ik92YWwtNS1Db3B5LTQiIGZpbGwtb3BhY2l0eT0iMC42IiBmaWxsPSIjRDFERUVEIiBjeD0iMjQzLjgzMzMzMyIgY3k9IjMwLjMzMzMzMzMiIHI9IjUuODMzMzMzMzMiPjwvY2lyY2xlPgogICAgICAgICAgICAgICAgICAgIDxjaXJjbGUgaWQ9Ik92YWwtNS1Db3B5LTUiIGZpbGw9IiNFMEI0QjciIGN4PSIxNzUuNTgzMzMzIiBjeT0iMjMyLjc1IiByPSI1LjI1Ij48L2NpcmNsZT4KICAgICAgICAgICAgICAgIDwvZz4KICAgICAgICAgICAgPC9nPgogICAgICAgIDwvZz4KICAgIDwvZz4KPC9zdmc+);
  		/* background-color: #112346; */
  		background-repeat: no-repeat;
  		background-position: center right;
  		background-size: 100%;
  	}
 
  	.login-container {
  		border-radius: 10px;
  		margin: 0px auto;
  		width: 350px;
  		padding: 30px 35px 15px 35px;
  		background: #fff;
  		border: 1px solid #eaeaea;
  		text-align: left;
  		box-shadow: 0 0 20px 2px rgba(0, 0, 0, 0.1);
  	}
 
  	.title {
  		margin: 0px auto 40px auto;
  		text-align: center;
  		color: #505458;
  	}
</style>kground-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+Cjxzdmcgd2lkdGg9IjEzNjFweCIgaGVpZ2h0PSI2MDlweCIgdmlld0JveD0iMCAwIDEzNjEgNjA5IiB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiPgogICAgPCEtLSBHZW5lcmF0b3I6IFNrZXRjaCA0Ni4yICg0NDQ5NikgLSBodHRwOi8vd3d3LmJvaGVtaWFuY29kaW5nLmNvbS9za2V0Y2ggLS0+CiAgICA8dGl0bGU+R3

   RegisterView.vue

<template>
    <div class="login-wrap">
        <el-form ref="form" :model="form">
          <h1 class="title">注册</h1>
          <el-form-item >
            <el-input type="text" v-model="form.username" placeholder="用户账号" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item >
            <el-input type="password" v-model="form.password" placeholder="用户密码" autocomplete="off"></el-input>
          </el-form-item>
        </el-form>
        <el-button type="primary" @click="register" style="width: 100%;">注册</el-button>
        <el-button type="primary" @click="doLogin" style="width: 100%;">返回登录</el-button>
    </div>
</template>


<script>
    import axios from 'axios';
    export default({

        data() {
            return {
                form: {
                    username: '',
                    password: ''
                }
            }
        },

        methods: {
            register() {
                axios.post('http://localhost:8081/register', {
                    username: this.form.username,
                    password: this.form.password
                }).then(res => {
                    console.log(res);
                    this.$message({
                        message: '注册成功',
                        type: 'success'
                    });
                    this.$router.push('/person');
                }).catch(err => {
                    console.log(err);
                    this.$message({
                        message: '注册失败'+err.message,
                        type: 'error'
                    })
                })
            },
            doLogin() {
                this.$router.push('/');
            }
        }


    })



</script>

(2) main.js,作请求和响应拦截

import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import 'element-ui/lib/theme-chalk/index.css';
import ElementUI from "element-ui";
import axios from "axios";

Vue.config.productionTip = false;
Vue.prototype.$axios = axios;

Vue.use(ElementUI);

//------------------请求拦截-------------------//
axios.interceptors.request.use(config => {
  //例:若存在token则带token
  const token = store.state.token;
  if (token) {
      config.headers.Authorization = token
  }
  return config;
}, err => {
  console.log("请求拦截=>", err);
  return err;
})

//------------------响应拦截-------------------//
//-------------对响应数据做点什么-------------//
axios.interceptors.response.use(res => {
  console.log("响应拦截=>", res.data);
  //例:后端数据处理错误,并返回错误原因;前端获取错误原因并展示
  if (res.data.success == false) {
      Message({
          message: res.data.data.message + ',请重试!',
          type: 'warning'
      });
  }
  console.log("响应拦截=>", res);
  return res ? res.data : res;
}, err => {
  console.log(err);
  //打印完整的错误信息
  console.log("响应拦截错误完整信息=>",err.response)
  //也可以在这里对不同的错误码做不同的展示处理
  throw err;
})


new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount("#app");

此处注意添加Element-ui依赖、axios依赖

2.后端

(1)mapper.xml

    <sql id="selectUser">
        select
        U.id,
        U.username,
        U.password
        from user U
    </sql>

    <select id="selectByUsername" parameterType="com.huaweisoft.test.zhansongtao.zhansongtao4.service.entity.User" resultType="com.huaweisoft.test.zhansongtao.zhansongtao4.service.entity.User">
        <include refid="selectUser"/>
        <where>
            <if test="username != null and username != ''"> and username = #{username}</if>
        </where>
    </select>

    <select id="selectByUserNameAndPassword" parameterType="com.huaweisoft.test.zhansongtao.zhansongtao4.service.entity.User" resultType="com.huaweisoft.test.zhansongtao.zhansongtao4.service.entity.User">
        <include refid="selectUser"/>
            <where>
                <if test="username != null and username != ''"> and username = #{username}</if>
                <if test="password != null and password != ''"> and password = #{password}</if>
            </where>
    </select>

    <insert id="insertUser" parameterType="com.huaweisoft.test.zhansongtao.zhansongtao4.service.entity.User">
        insert into user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="username != null and username != ''">username,</if>
            <if test="password != null and password != ''">password,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="username != null and username != ''">#{username},</if>
            <if test="password != null and password != ''">#{password},</if>
        </trim>
    </insert>


</mapper>

(2)mapper接口

@Mapper
public interface UserMapper extends tk.mybatis.mapper.common.Mapper<User>{

    User selectByUsername(User user);

    User selectByUserNameAndPassword(User user);

    int insertUser(User user);

}

(3)Service接口

public interface LoginService {
    boolean login(User user);

    void register(String username, String password);



}

(4)Service实现类

@Service
@AllArgsConstructor
public class LoginServiceImpl implements LoginService {

    private UserMapper userMapper;
    @Override
    public boolean login(User user) {
        if(StringUtils.isBlank(user.getUsername()) || StringUtils.isBlank(user.getPassword())){
            throw  new ServiceException("用户名或密码不能为空");
        }

        User user1 = userMapper.selectByUserNameAndPassword(user);

        if(user1 != null) {
            return true;
        }else {
            return false;
        }
    }

    @Override
    public void register(String username, String password) {
        if(StringUtils.isBlank(username) || StringUtils.isBlank(password)){
            throw  new ServiceException("用户名或密码不能为空");
        }

        if(!password.matches(".*\\d+.*")||!password.matches(".*[a-zA-Z]+.*")){
            throw  new ServiceException("密码必须包含大写字母、小写字母、数字");
        }
       //查询注册的用户名是否存在
        User user1 = userMapper.selectByUsername(new User(username));

        if(user1 != null){
            throw  new ServiceException("用户名已存在");
        }

        User user = new User();
        user.setUsername(username);
        user.setPassword(password);
        userMapper.insertUser(user);
    }

}

(5)Controller控制器

@RestController
@AllArgsConstructor
public class LoginController {

    private LoginService loginService;

    @PostMapping ("/login")
    public JSONResult login(@RequestBody User user) {
        boolean flag = loginService.login(user);
        if (flag) {
            return JSONResult.ok("登录成功!");
        } else {
            return JSONResult.errorMsg("登录失败!");
        }
    }

    @PostMapping("/register")
    public JSONResult register(@RequestBody User user) {
        loginService.register(user.getUsername(), user.getPassword());
        return JSONResult.ok("注册成功!");
    }

}

(6)实体类

@Data
@Table(name = "`user`")
@AllArgsConstructor
@NoArgsConstructor
public class User {

    /**
     * 主键
     */
    @Id
    @Column(name = "`id`")
    private Integer id;

    /**
     * 用户名
     */
    @Column(name = "`username`")
    private String username;

    /**
     * 密码
     */
    @Column(name = "`password`")
    private String password;


    public User(Integer id){
        this.id = id;
    }

    public User(String username){
        this.username = username;
    }
}

3.效果

 以我数据库中存储的:username:zhan  password:123456 示例

登录成功时: 

登录失败时:

注册:

 测试:

 页面可以跳转,说明注册添加账户成功

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/713576.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

六本入选!首批“十四五”职业教育国家规划教材书目

近日&#xff0c;教育部办公厅公布了首批“十四五”职业教育国家规划教材书目&#xff0c;其中广东泰迪智能科技股份有限公司携手院校联合编写的6本教材入选该名单。 入选首批“十四五” 职业教育国家规划教材介绍 高职“十四五”职业教育国家规划教材 Python编程基础(第2版)…

平时成绩综合评价与总成绩预测模型

已排除非本人创作部分 摘要 针对问题一&#xff0c;我们首先对所有团队的数据做了正态性检验&#xff0c;共x次作业&#xff0c;每次作业成绩分布均可用正态分布描述。其次&#xff0c;我们对团队之间的成绩变化做了格兰杰因果检验&#xff0c;列出了成绩变化相关的一部分团队…

STL补充:STL中遵循的左闭右开原则/STL随机访问

文章目录 左闭右开原则示例&#xff1a;示例中erase的用法不能写成s.erase(s.begin()left)的原因 STL中支持随机访问的迭代器 左闭右开原则 在 C 中&#xff0c;容器&#xff08;如 vector&#xff0c;set&#xff0c;map 等&#xff09;的迭代器都遵循左闭右开的原则。 也就…

微服务- Eureka 注册

1. 首先从结构方面来说 单体架构&#xff1a;比较适合用于小型项目&#xff08;像一些学生管理系统&#xff09;&#xff0c;简单方便&#xff0c;高度耦合 分布式架构&#xff1a;松耦合&#xff0c;扩展性好&#xff0c;但架构复杂&#xff0c;难度大&#xff0c;适合大型互联…

CIO40---3个亿数字化供应链实战

2019年某天&#xff0c;我被总裁叫到办公室&#xff0c;我当是VP A&#xff1a;企业情况 一家A股上市 市值150亿&#xff0c;年销售50亿&#xff0c; 员工4000人&#xff0c;全国4个工厂 家庭企业&#xff0c;高管老人多 经销商模式&#xff0c;总代模式&#xff0c;工程…

unserialize3

看着这个源码长度&#xff0c;就觉着比较简单 本题就一个__wakeup方法需要绕过&#xff0c;但是不对哦没有提示也不知道该参数得多少呀 本来都要复制进编译器写了&#xff0c;发现源码闭合有点问题&#xff0c;可能是做了隐藏 解题步骤 实在找不到了&#xff0c;就尝试了一下fl…

81、基于STM32单片机的颜色识别 TCS3200 RGB 检测系统设计(程序+原理图+PCB源文件+参考论文+开题报告+任务书+设计资料+元器件清单等)

摘 要 随着现代工业生产向高速化、自动化方向的发展&#xff0c;色彩识别广泛应用于各种工业检测和自动控制领域&#xff0c;而生产过程中长期以来由人眼起主导作用的颜色识别工作将越来越多地被相应的颜色传感器所替代。如&#xff1a;各种物体表面颜色识别&#xff08;产品包…

什么是三极管推挽电路

这是一个三极管推挽电路&#xff0c;上面是一个NPN的三极管&#xff0c;下面是一个PNP的三极管。 当输入信号为VCC时&#xff0c;上面的三极管导通&#xff0c;下面的三极管截止&#xff0c;输出信号为VCC-0.7V&#xff0c;这个0.7V就是上面NPN三极管BE间的导通压降 当输入信号…

Spring Bean 作用域的定义

在 Spring 配置中&#xff0c;我们可以通过 scope 属性来定义 Spring Bean 的作用域&#xff0c;可以接受 5 个内建的值&#xff0c;分别代表 5 种作用域类型&#xff0c;下面给大家详细总结一下&#xff1a; 1、singleton&#xff0c;用来定义一个 Bean 为单例&#xff0c;也…

【MATLAB第50期】基于MATLAB的RELM-LOO多输入单输出回归分类预测算法与RELM及ELM进行对比

【MATLAB第50期】基于MATLAB的RELM-LOO多输入单输出回归&分类预测算法与RELM及ELM进行对比 引言 RELM-LOO即通过LOO计算效率方法对其RELM模型正则化C系数进行寻优。 对于进化算法寻优来说&#xff0c; 结果更稳定。 可参考以下文献&#xff1a; [1] Shao Z , Er M J , W…

小红书测评类产品种草文案怎么写?品牌方必看

小红书逐渐成为了越来越多年轻人购物和分享的主流平台。测评类产品的种草文案尤为重要&#xff0c;因为它可以帮助消费者更好地了解产品的性能、使用方法以及适用场景&#xff0c;从而为购物决策提供参考。这个时候将某个产品植入进去&#xff0c;就会更容易被用户所接受&#…

C++高级编程01

目录 1、双冒号作用域运算符 2、namespace命名空间 3、using声明以及using编译指令 using 声明 4、C对C语言的增强 4、const链接属性 5、const分配内存情况 6、尽量用const代替define 7、引用 1、双冒号作用域运算符 ::代表作用域 如果前面什么都不添加 代表全局作用…

K8S资源控制器管理

资源控制器 1 资源控制器1.1 控制基础1.1.1 控制原理1.1.2 控制对象 1.2 标签选择器1.2.1 标签基础1.2.2 标签选择器 1.3 副本控制器1.3.1 RC&RS1.3.2 Deploy基础1.3.3 Deploy进阶1.3.4 DaemonSet1.3.5 任务控制器 1.4 监视控制器1.4.1 metrics服务1.4.2 HPA实践 1 资源控制…

Git 推送教程

一般 add commit push即可。Git全流程&#xff1a; git init #初始化仓库 git add .文件名 #添加文件&#xff0c;添加全部文件可以直接写. git commit -m "信息" #提交到本地仓库 git remote add origin 远程仓库地址 #链接远程仓库&#xff0c;创建主分支 git p…

【每日一题】2. 两数相加

【每日一题】2. 两数相加 2. 两数相加题目描述解题思路 2. 两数相加 题目描述 给你两个 非空 的链表&#xff0c;表示两个非负的整数。它们每位数字都是按照 逆序 的方式存储的&#xff0c;并且每个节点只能存储 一位 数字。 请你将两个数相加&#xff0c;并以相同形式返回一…

MySQL的体系架构

文章目录 前言MySQL的Server层MySQL的存储引擎1&#xff09;InnoDB 存储引擎2&#xff09;MyISAM 存储引擎3&#xff09;Memory 存储引擎 前言 在学习一种事务之前&#xff0c;我们需要先了解事物的基本组成结构&#xff0c;清楚了事物的基本组成结构之后&#xff0c;我们才能…

QCC51XX---chain是什么?

QCC51XX---系统学习目录_嵌入式学习_force的博客-CSDN博客 高通的DSP对很多人来说还是比较难以理解与操作的,DSP里最基本的是要认识音频的处理链路,也就是平台中的chain。他是由多个模块(operator)连接起来的,连接的方法sink和earbud有些不同,这里会从6.x开始sink的chain…

shell判断程序是否运行

一、需求 服务部署在linux上&#xff0c;要求服务器上的服务可以一直保持正常运行 二、问题 在linux上部署的微服务&#xff0c;不知道什么原因过一段时间就自己停掉了&#xff0c;无法启动。 三、解决办法 添加angle守护进程&#xff0c;通过定时执行脚本来判断程序是否运行…

AI 绘画 - 建筑绘图辅助设计之模型训练

前情提要 2023-06-18 周日 杭州 小雨 小记: 昨天搞的好累&#xff0c;10点左右就想着先躺一会儿&#xff0c;然后就睡过去了&#xff0c;很奇怪&#xff0c;如果进行 AI 绘画&#xff0c;晚上就会做很奇怪的梦&#xff0c;说不上来的那种感觉&#xff0c;就是莫名的不舒服。 …

微信怎么能自动回复?

有些小伙伴可能有多个微信号来进行业务活动&#xff0c;一天收到的信息太多&#xff0c;眼花缭乱&#xff0c;回复不过来&#xff0c;就想在微信可不可以有个自动回复消息&#xff0c;就可以通过自动回复引导用户看到想让他们看到的。这样就可以降低工作量的同时&#xff0c;提…