当前位置: 首页 > 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 来编译一个文件…...

在软件开发中正确使用MySQL日期时间类型的深度解析

在日常软件开发场景中&#xff0c;时间信息的存储是底层且核心的需求。从金融交易的精确记账时间、用户操作的行为日志&#xff0c;到供应链系统的物流节点时间戳&#xff0c;时间数据的准确性直接决定业务逻辑的可靠性。MySQL作为主流关系型数据库&#xff0c;其日期时间类型的…...

【根据当天日期输出明天的日期(需对闰年做判定)。】2022-5-15

缘由根据当天日期输出明天的日期(需对闰年做判定)。日期类型结构体如下&#xff1a; struct data{ int year; int month; int day;};-编程语言-CSDN问答 struct mdata{ int year; int month; int day; }mdata; int 天数(int year, int month) {switch (month){case 1: case 3:…...

脑机新手指南(八):OpenBCI_GUI:从环境搭建到数据可视化(下)

一、数据处理与分析实战 &#xff08;一&#xff09;实时滤波与参数调整 基础滤波操作 60Hz 工频滤波&#xff1a;勾选界面右侧 “60Hz” 复选框&#xff0c;可有效抑制电网干扰&#xff08;适用于北美地区&#xff0c;欧洲用户可调整为 50Hz&#xff09;。 平滑处理&…...

PHP和Node.js哪个更爽?

先说结论&#xff0c;rust完胜。 php&#xff1a;laravel&#xff0c;swoole&#xff0c;webman&#xff0c;最开始在苏宁的时候写了几年php&#xff0c;当时觉得php真的是世界上最好的语言&#xff0c;因为当初活在舒适圈里&#xff0c;不愿意跳出来&#xff0c;就好比当初活在…...

SCAU期末笔记 - 数据分析与数据挖掘题库解析

这门怎么题库答案不全啊日 来简单学一下子来 一、选择题&#xff08;可多选&#xff09; 将原始数据进行集成、变换、维度规约、数值规约是在以下哪个步骤的任务?(C) A. 频繁模式挖掘 B.分类和预测 C.数据预处理 D.数据流挖掘 A. 频繁模式挖掘&#xff1a;专注于发现数据中…...

CMake基础:构建流程详解

目录 1.CMake构建过程的基本流程 2.CMake构建的具体步骤 2.1.创建构建目录 2.2.使用 CMake 生成构建文件 2.3.编译和构建 2.4.清理构建文件 2.5.重新配置和构建 3.跨平台构建示例 4.工具链与交叉编译 5.CMake构建后的项目结构解析 5.1.CMake构建后的目录结构 5.2.构…...

理解 MCP 工作流:使用 Ollama 和 LangChain 构建本地 MCP 客户端

&#x1f31f; 什么是 MCP&#xff1f; 模型控制协议 (MCP) 是一种创新的协议&#xff0c;旨在无缝连接 AI 模型与应用程序。 MCP 是一个开源协议&#xff0c;它标准化了我们的 LLM 应用程序连接所需工具和数据源并与之协作的方式。 可以把它想象成你的 AI 模型 和想要使用它…...

【第二十一章 SDIO接口(SDIO)】

第二十一章 SDIO接口 目录 第二十一章 SDIO接口(SDIO) 1 SDIO 主要功能 2 SDIO 总线拓扑 3 SDIO 功能描述 3.1 SDIO 适配器 3.2 SDIOAHB 接口 4 卡功能描述 4.1 卡识别模式 4.2 卡复位 4.3 操作电压范围确认 4.4 卡识别过程 4.5 写数据块 4.6 读数据块 4.7 数据流…...

Python实现prophet 理论及参数优化

文章目录 Prophet理论及模型参数介绍Python代码完整实现prophet 添加外部数据进行模型优化 之前初步学习prophet的时候&#xff0c;写过一篇简单实现&#xff0c;后期随着对该模型的深入研究&#xff0c;本次记录涉及到prophet 的公式以及参数调优&#xff0c;从公式可以更直观…...

三体问题详解

从物理学角度&#xff0c;三体问题之所以不稳定&#xff0c;是因为三个天体在万有引力作用下相互作用&#xff0c;形成一个非线性耦合系统。我们可以从牛顿经典力学出发&#xff0c;列出具体的运动方程&#xff0c;并说明为何这个系统本质上是混沌的&#xff0c;无法得到一般解…...