当前位置: 首页 > news >正文

微服务系列文章之 Springboot+Vue实现登录注册

一、springBoot

创建springBoot项目

分为三个包,分别为controller,service, dao以及resource目录下的xml文件。

UserController.java

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

package springbootmybatis.controller;

import org.springframework.web.bind.annotation.CrossOrigin;

import org.springframework.web.bind.annotation.PostMapping;

import org.springframework.web.bind.annotation.RequestBody;

import org.springframework.web.bind.annotation.RestController;

import springbootmybatis.pojo.User;

import springbootmybatis.service.UserService;

import javax.annotation.Resource;

@RestController

public class UserController {

    @Resource

    UserService userService;

    @PostMapping("/register/")

    @CrossOrigin("*")

    String register(@RequestBody User user) {

        System.out.println("有人请求注册!");

        int res = userService.register(user.getAccount(), user.getPassword());

        if(res==1) {

            return "注册成功";

        } else {

            return "注册失败";

        }

    }

    @PostMapping("/login/")

    @CrossOrigin("*")

    String login(@RequestBody User user) {

        int res = userService.login(user.getAccount(), user.getPassword());

        if(res==1) {

            return "登录成功";

        } else {

            return "登录失败";

        }

    }

}

UserService.java

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

package springbootmybatis.service;

import org.springframework.stereotype.Service;

import springbootmybatis.dao.UserMapper;

import javax.annotation.Resource;

@Service

public class UserService {

    @Resource

    UserMapper userMapper;

    public int register(String account, String password) {

        return userMapper.register(account, password);

    }

    public int login(String account, String password) {

        return userMapper.login(account, password);

    }

}

User.java (我安装了lombok插件)

1

2

3

4

5

6

7

8

9

package springbootmybatis.pojo;

import lombok.Data;

@Data

public class User {

    private String account;

    private String password;

}

UserMapper.java

1

2

3

4

5

6

7

8

9

10

package springbootmybatis.dao;

import org.apache.ibatis.annotations.Mapper;

@Mapper

public interface UserMapper {

    int register(String account, String password);

    int login(String account, String password);

}

UserMapper.xml

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE mapper

        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"

        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="springbootmybatis.dao.UserMapper">

    <insert id="register">

       insert into User (account, password) values (#{account}, #{password});

    </insert>

    <select id="login" resultType="Integer">

        select count(*) from User where account=#{account} and password=#{password};

    </select>

</mapper>

主干配置

application.yaml

1

2

3

4

5

6

7

8

9

10

11

12

server.port: 8000

spring:

  datasource:

    username: root

    password: 123456

    url: jdbc:mysql://localhost:3306/community?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8

    driver-class-name: com.mysql.cj.jdbc.Driver

mybatis:

    type-aliases-package: springbootmybatis.pojo

    mapper-locations: classpath:mybatis/mapper/*.xml

    configuration:

      map-underscore-to-camel-case: true

数据库需要建相应得到表

1

2

3

4

CREATE TABLE `user` (

  `account` varchar(255) COLLATE utf8_bin DEFAULT NULL,

  `password` varchar(255) COLLATE utf8_bin DEFAULT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

二、创建VUE项目

安装node,npm,配置环境变量。
配置cnpm仓库,下载的时候可以快一些。

1

npm i -g cnpm --registry=https://registry.npm.taobao.org

安装VUE

1

npm i -g vue-cli

初始化包结构

1

vue init webpack project

启动项目

1

2

3

4

5

6

# 进入项目目录

cd vue-01

# 编译

npm install

# 启动

npm run dev

修改项目文件,按照如下结构

 

APP.vue

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

<template>

  <div id="app">

    <router-view/>

  </div>

</template>

<script>

export default {

  name: 'App'

}

</script>

<style>

</style>

welcome.vue

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

<template>

  <div>

    <el-input v-model="account" placeholder="请输入帐号"></el-input>

    <el-input v-model="password" placeholder="请输入密码" show-password></el-input>

    <el-button type="primary" @click="login">登录</el-button>

    <el-button type="primary" @click="register">注册</el-button>

  </div>

</template>

<script>

export default {

  name: 'welcome',

  data () {

    return {

      account: '',

      password: ''

    }

  },

  methods: {

    register: function () {

      this.axios.post('/api/register/', {

        account: this.account,

        password: this.password

      }).then(function (response) {

        console.log(response);

      }).catch(function (error) {

        console.log(error);

      });

      // this.$router.push({path:'/registry'});

    },

    login: function () {

      this.axios.post('/api/login/', {

        account: this.account,

        password: this.password

      }).then(function () {

        alert('登录成功');

      }).catch(function (e) {

        alert(e)

      })

      // this.$router.push({path: '/board'});

    }

  }

}

</script>

<style scoped>

</style>

main.js

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

// The Vue build version to load with the `import` command

// (runtime-only or standalone) has been set in webpack.base.conf with an alias.

import Vue from 'vue'

import App from './App'

import router from './router'

import ElementUI from 'element-ui'

import 'element-ui/lib/theme-chalk/index.css'

import axios from 'axios'

import VueAxios from 'vue-axios'

Vue.use(VueAxios, axios)

Vue.use(ElementUI)

Vue.config.productionTip = false

/* eslint-disable no-new */

new Vue({

  el: '#app',

  router,

  components: {App},

  template: '<App/>'

})

router/index.js

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

import Vue from 'vue'

import Router from 'vue-router'

import welcome from '@/components/welcome'

Vue.use(Router)

export default new Router({

  routes: [

    {

      path: '/',

      name: 'welcome',

      component: welcome

    }

  ]

})

config/index.js

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

'use strict'

// Template version: 1.3.1

// see http://vuejs-templates.github.io/webpack for documentation.

const path = require('path')

module.exports = {

  dev: {

    // Paths

    assetsSubDirectory: 'static',

    assetsPublicPath: '/',

    proxyTable: {

      '/api': {

        target: 'http://localhost:8000', // 后端接口的域名

        // secure: false,  // 如果是https接口,需要配置这个参数

        changeOrigin: true, // 如果接口跨域,需要进行这个参数配置

        pathRewrite: {

          '^/api': '' //路径重写,当你的url带有api字段时如/api/v1/tenant,

          //可以将路径重写为与规则一样的名称,即你在开发时省去了再添加api的操作

        }

      }

    },

    // Various Dev Server settings

    host: 'localhost', // can be overwritten by process.env.HOST

    port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined

    autoOpenBrowser: false,

    errorOverlay: true,

    notifyOnErrors: true,

    poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-

    // Use Eslint Loader?

    // If true, your code will be linted during bundling and

    // linting errors and warnings will be shown in the console.

    useEslint: true,

    // If true, eslint errors and warnings will also be shown in the error overlay

    // in the browser.

    showEslintErrorsInOverlay: false,

    /**

     * Source Maps

     */

    // https://webpack.js.org/configuration/devtool/#development

    devtool: 'cheap-module-eval-source-map',

    // If you have problems debugging vue-files in devtools,

    // set this to false - it *may* help

    // https://vue-loader.vuejs.org/en/options.html#cachebusting

    cacheBusting: true,

    cssSourceMap: true

  },

  build: {

    // Template for index.html

    index: path.resolve(__dirname, '../dist/index.html'),

    // Paths

    assetsRoot: path.resolve(__dirname, '../dist'),

    assetsSubDirectory: 'static',

    assetsPublicPath: '/',

    /**

     * Source Maps

     */

    productionSourceMap: true,

    // https://webpack.js.org/configuration/devtool/#production

    devtool: '#source-map',

    // Gzip off by default as many popular static hosts such as

    // Surge or Netlify already gzip all static assets for you.

    // Before setting to `true`, make sure to:

    // npm install --save-dev compression-webpack-plugin

    productionGzip: false,

    productionGzipExtensions: ['js', 'css'],

    // Run the build command with an extra argument to

    // View the bundle analyzer report after build finishes:

    // `npm run build --report`

    // Set to `true` or `false` to always turn it on or off

    bundleAnalyzerReport: process.env.npm_config_report

  }

}

输入账号密码,实现简单的注册,登录功能。

相关文章:

微服务系列文章之 Springboot+Vue实现登录注册

一、springBoot 创建springBoot项目 分为三个包&#xff0c;分别为controller&#xff0c;service&#xff0c; dao以及resource目录下的xml文件。 UserController.java 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 …...

【Docker】如何在设计 dockerfile 过程中,设置容器启动后的定时任务

如何在设计 dockerfile 过程中&#xff0c;设置容器启动后的定时任务 jwensh 2023.08.14 文章目录 如何在设计 dockerfile 过程中&#xff0c;设置容器启动后的定时任务1. 基于 alpine 设计 dockerfile 过程中&#xff0c;设置容器启动后的定时任务2. 基于 CentOS 设计 Dockerf…...

【leetcode】第三章 哈希表part01

242.有效的字母异位词 使用HashMap public boolean isAnagram(String s, String t) {HashMap<Character,Integer> map new HashMap();int sLen s.length();int tLen t.length();if (sLen ! tLen) return false;// 统计词频for (int i 0; i < s.length(); i) {ch…...

Docker中Tomcat部署步骤

第一次访问没有东西。...

pycharm 安装库

这是另一种方式。 搜索到的安装库的方式多数是&#xff1a;在桌面上winR键运行终端&#xff0c;输入命令&#xff0c;安装不了&#xff0c;发现安装不了。 1、打开pycharm&#xff1b; 2、软件下部的Terminal终端(需要运行一个代码才能出现&#xff0c;任何代码都可)&#xf…...

使用 Ploomber、Arima、Python 和 Slurm 进行时间序列预测

推荐&#xff1a;使用 NSDT场景编辑器助你快速搭建可二次编辑的3D应用场景 简短的笔记本说明 笔记本由 8 个任务组成&#xff0c;如下图所示。它包括建模的大多数基本步骤 - 获取数据清理、拟合、超参数调优、验证和可视化。作为捷径&#xff0c;我拿起笔记本并使用Soorgeon工具…...

springboot第35集:微服务与flutter安卓App开发

Google Playplay.google.com/apps/publis…[1]应用宝open.qq.com/[2]百度手机助手app.baidu.com/[3]360 手机助手dev.360.cn/[4]vivo 应用商店dev.vivo.com.cn/[5]OPPO 软件商店&#xff08;一加&#xff09;open.oppomobile.com/[6]小米应用商店dev.mi.com/[7]华为应用市场dev…...

java 把list转成json

在Java中&#xff0c;将List转换成JSON格式是非常常见的任务。JSON是一种轻巧的数据交换格式&#xff0c;非常适合于Web应用程序&#xff0c;特别是前端开发。 使用Java将List转换成JSON格式的最简单方法是通过JSON库。最常用的JSON库是 Jackson&#xff0c;它提供了快速&…...

R语言实现随机生存森林(2)

library(survival) library(randomForestSRC) help(package"randomForestSRC") #构建普通的随机生存森林 data(cancer,package"survival") lung$status<-lung$status-1 rfsrc.fit1 <- rfsrc(Surv(time, status) ~ ., lung,ntree 100,block.size 1,…...

泛型类接口方法学习

一、泛型 1 概念 泛型(Generics)&#xff0c;广泛的类型。最大用途是给集合容器添加标签&#xff0c;让开发人员知道容器里面放到是什么类型&#xff0c;并且自动对放入集合的元素进行类型检查。 类比实参和形参&#xff0c;我们在对方法中的变量操作时&#xff0c;并没有指…...

Docker自动化部署安装(十)之安装SonarQube

这里选择的是&#xff1a; sonarqube:9.1.0-community (推荐使用) postgres:9.6.23 数据库(sonarqube7.9及以后便不再支持mysql&#xff0c;版本太低的话里面的一些插件会下载不成功的) 1、docker-sonarqube.yml文件 version: 3 services:sonarqube:container_name: sonar…...

[QT/C++]如何得知鼠标事件是由触摸事件转换而来的,使得鼠标触摸事件分离

依据来源&#xff1a;https://doc.qt.io/qt-5/qml-qtquick-mouseevent.html 具体是在event事件或者mouse系列事件中捕获到鼠标事件后&#xff0c;用如下代码判断鼠标事件是否由触摸事件转换而来的 if(mouseEvent->source()Qt::MouseEventSynthesizedBySystem){qDebug()<&…...

消防态势标绘工具,为消防基层工作助力

背景介绍 无人机测绘技术在消防领域的应用越来越普及&#xff0c;高清的二维正射影像和倾斜摄影实景三维模型能为消防态势标绘提供高质量的素材&#xff0c;消防队急需一个简便易用的、能够基于这些二三维的高清地图成果进行态势标绘的工具软件&#xff0c;使得消防“六熟悉”…...

网络协议栈-基础知识

1、分层模型 1.1、OSI七层模型 1、OSI&#xff08;Open System Interconnection&#xff0c;开放系统互连&#xff09;七层网络模型称为开放式系统互联参考模型 &#xff0c;是一个逻辑上的定义&#xff0c;一个规范&#xff0c;它把网络从逻辑上分为了7层。 2、每一层都有相关…...

[Mongodb 5.0]聚合操作

本文对应Aggregation Operations — MongoDB Manual 正文 此章节主要介绍了Aggregation Pipeline&#xff0c;其实就是将若干个聚合操作放在管道中进行执行&#xff0c;每一个聚合操作的结果作为下一个聚合操作的输入&#xff0c;每个聚合指令被称为一个stage。 在正式开始学…...

Shell 变量

Shell 变量 定义变量时&#xff0c;变量名不加美元符号&#xff08;$&#xff0c;PHP语言中变量需要&#xff09;&#xff0c;如&#xff1a; your_name"runoob.com" 注意&#xff0c;变量名和等号之间不能有空格&#xff0c;这可能和你熟悉的所有编程语言都不一样…...

SRM订单管理:优化供应商关系

一、概述SRM订单管理的概念&#xff1a; SRM订单管理是指在供应商关系管理过程中&#xff0c;有效管理和控制订单的创建、处理和交付。它涉及与供应商之间的沟通、合作和协调&#xff0c;旨在实现订单的准确性、可靠性和及时性。 二、SRM订单管理的流程&#xff1a; 1. 订单创…...

Unity 实现2D地面挖洞!涂抹地形(碰撞部分,方法二)

文章目录 前言一、初始化虚拟点1.1点结构:1.2每个点有的状态:1.3生成点结构: 二、实例化边缘碰撞盒2.1计算生成边缘碰撞盒 三、涂抹部分3.1.虚拟点3.2.鼠标点3.3.内圈3.4.外圈 四、关于优化结语: 前言 老规矩先上效果图 继上一篇涂抹地形文章讲解发出后&#xff0c;有不少网友…...

简化Gerber数据传输过程丨GC PowerPlace简介

离线编程&#xff0c;保持高效 GC PowerPlace提供了客户驱动的增强功能和新功能&#xff0c;以简化Gerber数据传输过程。GC PowerPlace是汇编编程的焦点&#xff0c;它接受几乎任何来源的数据&#xff0c;并为大多数PCB制造应用程序生成程序和文件。 功能特征 01、主要特点 …...

rust关于项目结构包,Crate和mod和目录的组织

rust 最近开始学习rust语言。感觉这门语言相对java确实是难上很多。开几个文章把遇到的问题记录一下 rust关于包&#xff0c;Crate 关于包&#xff0c;Crate这块先看看官方书籍怎么说的 crate 是 Rust 在编译时最小的代码单位。如果你用 rustc 而不是 cargo 来编译一个文件…...

KubeSphere 容器平台高可用:环境搭建与可视化操作指南

Linux_k8s篇 欢迎来到Linux的世界&#xff0c;看笔记好好学多敲多打&#xff0c;每个人都是大神&#xff01; 题目&#xff1a;KubeSphere 容器平台高可用&#xff1a;环境搭建与可视化操作指南 版本号: 1.0,0 作者: 老王要学习 日期: 2025.06.05 适用环境: Ubuntu22 文档说…...

Leetcode 3577. Count the Number of Computer Unlocking Permutations

Leetcode 3577. Count the Number of Computer Unlocking Permutations 1. 解题思路2. 代码实现 题目链接&#xff1a;3577. Count the Number of Computer Unlocking Permutations 1. 解题思路 这一题其实就是一个脑筋急转弯&#xff0c;要想要能够将所有的电脑解锁&#x…...

spring:实例工厂方法获取bean

spring处理使用静态工厂方法获取bean实例&#xff0c;也可以通过实例工厂方法获取bean实例。 实例工厂方法步骤如下&#xff1a; 定义实例工厂类&#xff08;Java代码&#xff09;&#xff0c;定义实例工厂&#xff08;xml&#xff09;&#xff0c;定义调用实例工厂&#xff…...

[10-3]软件I2C读写MPU6050 江协科技学习笔记(16个知识点)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16...

uniapp中使用aixos 报错

问题&#xff1a; 在uniapp中使用aixos&#xff0c;运行后报如下错误&#xff1a; AxiosError: There is no suitable adapter to dispatch the request since : - adapter xhr is not supported by the environment - adapter http is not available in the build 解决方案&…...

Element Plus 表单(el-form)中关于正整数输入的校验规则

目录 1 单个正整数输入1.1 模板1.2 校验规则 2 两个正整数输入&#xff08;联动&#xff09;2.1 模板2.2 校验规则2.3 CSS 1 单个正整数输入 1.1 模板 <el-formref"formRef":model"formData":rules"formRules"label-width"150px"…...

C++:多态机制详解

目录 一. 多态的概念 1.静态多态&#xff08;编译时多态&#xff09; 二.动态多态的定义及实现 1.多态的构成条件 2.虚函数 3.虚函数的重写/覆盖 4.虚函数重写的一些其他问题 1&#xff09;.协变 2&#xff09;.析构函数的重写 5.override 和 final关键字 1&#…...

Kafka入门-生产者

生产者 生产者发送流程&#xff1a; 延迟时间为0ms时&#xff0c;也就意味着每当有数据就会直接发送 异步发送API 异步发送和同步发送的不同在于&#xff1a;异步发送不需要等待结果&#xff0c;同步发送必须等待结果才能进行下一步发送。 普通异步发送 首先导入所需的k…...

MySQL JOIN 表过多的优化思路

当 MySQL 查询涉及大量表 JOIN 时&#xff0c;性能会显著下降。以下是优化思路和简易实现方法&#xff1a; 一、核心优化思路 减少 JOIN 数量 数据冗余&#xff1a;添加必要的冗余字段&#xff08;如订单表直接存储用户名&#xff09;合并表&#xff1a;将频繁关联的小表合并成…...

Xela矩阵三轴触觉传感器的工作原理解析与应用场景

Xela矩阵三轴触觉传感器通过先进技术模拟人类触觉感知&#xff0c;帮助设备实现精确的力测量与位移监测。其核心功能基于磁性三维力测量与空间位移测量&#xff0c;能够捕捉多维触觉信息。该传感器的设计不仅提升了触觉感知的精度&#xff0c;还为机器人、医疗设备和制造业的智…...