最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

springboot+VUE實(shí)現(xiàn)登錄注冊(cè)

 更新時(shí)間:2021年05月27日 17:04:37   作者:摔跤吧兒  
這篇文章主要為大家詳細(xì)介紹了springboot+VUE實(shí)現(xiàn)登錄注冊(cè),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了springboot+VUE實(shí)現(xiàn)登錄注冊(cè)的具體代碼,供大家參考,具體內(nèi)容如下

一、springBoot

創(chuàng)建springBoot項(xiàng)目

分為三個(gè)包,分別為controller,service, dao以及resource目錄下的xml文件。

UserController.java

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("有人請(qǐng)求注冊(cè)!");
        int res = userService.register(user.getAccount(), user.getPassword());
        if(res==1) {
            return "注冊(cè)成功";
        } else {
            return "注冊(cè)失敗";
        }
    }

    @PostMapping("/login/")
    @CrossOrigin("*")
    String login(@RequestBody User user) {
        int res = userService.login(user.getAccount(), user.getPassword());
        if(res==1) {
            return "登錄成功";
        } else {
            return "登錄失敗";
        }
    }
}

UserService.java

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插件)

package springbootmybatis.pojo;

import lombok.Data;

@Data
public class User {
    private String account;
    private String password;
}

UserMapper.java

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

<?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

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

數(shù)據(jù)庫需要建相應(yīng)得到表

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;

二、創(chuàng)建VUE項(xiàng)目

安裝node,npm,配置環(huán)境變量。
配置cnpm倉庫,下載的時(shí)候可以快一些。

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

安裝VUE

npm i -g vue-cli

初始化包結(jié)構(gòu)

vue init webpack project

啟動(dòng)項(xiàng)目

# 進(jìn)入項(xiàng)目目錄
cd vue-01
# 編譯
npm install
# 啟動(dòng)
npm run dev

修改項(xiàng)目文件,按照如下結(jié)構(gòu)

APP.vue

<template>
  <div id="app">
    <router-view/>
  </div>
</template>

<script>
export default {
  name: 'App'
}
</script>

<style>

</style>

welcome.vue

<template>
  <div>
    <el-input v-model="account" placeholder="請(qǐng)輸入帳號(hào)"></el-input>
    <el-input v-model="password" placeholder="請(qǐng)輸入密碼" show-password></el-input>
    <el-button type="primary" @click="login">登錄</el-button>
    <el-button type="primary" @click="register">注冊(cè)</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

// 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

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

'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接口,需要配置這個(gè)參數(shù)
        changeOrigin: true, // 如果接口跨域,需要進(jìn)行這個(gè)參數(shù)配置
        pathRewrite: {
          '^/api': '' //路徑重寫,當(dāng)你的url帶有api字段時(shí)如/api/v1/tenant,
          //可以將路徑重寫為與規(guī)則一樣的名稱,即你在開發(fā)時(shí)省去了再添加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
  }
}

輸入賬號(hào)密碼,實(shí)現(xiàn)簡(jiǎn)單的注冊(cè),登錄功能。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue+vuecli+webpack中使用mockjs模擬后端數(shù)據(jù)的示例

    vue+vuecli+webpack中使用mockjs模擬后端數(shù)據(jù)的示例

    本篇文章主要介紹了vue+vuecli+webpack中使用mockjs模擬后端數(shù)據(jù)的示例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。
    2017-10-10
  • element-plus一個(gè)vue3.xUI框架(element-ui的3.x 版初體驗(yàn))

    element-plus一個(gè)vue3.xUI框架(element-ui的3.x 版初體驗(yàn))

    這篇文章主要介紹了element-plus一個(gè)vue3.xUI框架(element-ui的3.x 版初體驗(yàn)),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-12-12
  • vue3+ts實(shí)現(xiàn)一個(gè)表單組件的詳細(xì)代碼

    vue3+ts實(shí)現(xiàn)一個(gè)表單組件的詳細(xì)代碼

    這篇文章主要介紹了vue3+ts實(shí)現(xiàn)一個(gè)表單組件的詳細(xì)代碼,確保通過axios調(diào)用后端接口來獲取省市區(qū)和街道數(shù)據(jù),并在選擇省市區(qū)時(shí)加載相應(yīng)的街道數(shù)據(jù),需要的朋友可以參考下
    2024-07-07
  • Vue鼠標(biāo)滾輪滾動(dòng)切換路由效果的實(shí)現(xiàn)方法

    Vue鼠標(biāo)滾輪滾動(dòng)切換路由效果的實(shí)現(xiàn)方法

    這篇文章主要介紹了Vue鼠標(biāo)滾輪滾動(dòng)切換路由效果的實(shí)現(xiàn)方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-08-08
  • Vue3中ref數(shù)組的監(jiān)聽實(shí)現(xiàn)方式

    Vue3中ref數(shù)組的監(jiān)聽實(shí)現(xiàn)方式

    Vue3中監(jiān)聽ref定義的數(shù)組,需根據(jù)監(jiān)聽需求選擇合適的監(jiān)聽方法,對(duì)于空數(shù)組,推薦使用深度監(jiān)聽來捕捉數(shù)組內(nèi)部變化,同時(shí),確保修改數(shù)組的方式是響應(yīng)式的,以保證監(jiān)聽器能正常工作,根據(jù)具體需求,可以選擇直接深度監(jiān)聽、監(jiān)聽數(shù)組長(zhǎng)度變化或提取屬性監(jiān)聽等方案
    2025-10-10
  • 如何通過Vue3+Element?Plus自定義彈出框組件

    如何通過Vue3+Element?Plus自定義彈出框組件

    這篇文章主要給大家介紹了關(guān)于如何通過Vue3+Element?Plus自定義彈出框組件的相關(guān)資料,彈窗是前端開發(fā)中的一種常見需求,文中通過代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2024-05-05
  • vue 使用餓了么UI仿寫teambition的篩選功能

    vue 使用餓了么UI仿寫teambition的篩選功能

    這篇文章主要介紹了vue 如何使用餓了么UI仿寫teambition的篩選功能,幫助大家更好的理解和學(xué)習(xí)使用vue框架
    2021-03-03
  • Vue.js的復(fù)用組件開發(fā)流程完整記錄

    Vue.js的復(fù)用組件開發(fā)流程完整記錄

    這篇文章主要給大家介紹了關(guān)于Vue.js的復(fù)用組件開發(fā)流程的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-11-11
  • 從零開始搭建vue移動(dòng)端項(xiàng)目到上線的步驟

    從零開始搭建vue移動(dòng)端項(xiàng)目到上線的步驟

    這篇文章主要介紹了從零開始搭建vue移動(dòng)端項(xiàng)目到上線的步驟,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-10-10
  • 解決vue ui報(bào)錯(cuò)Couldn‘t parse bundle asset“C:\Users\Administrator\vue_project1\dist\js\about.js“. Analyzer

    解決vue ui報(bào)錯(cuò)Couldn‘t parse bundle asset“C:

    這篇文章主要介紹了解決vue ui報(bào)錯(cuò)Couldn‘t parse bundle asset“C:\Users\Administrator\vue_project1\dist\js\about.js“. Analyzer問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-04-04

最新評(píng)論

晋州市| 湘乡市| 漯河市| 宜兰县| 扶风县| 肇庆市| 景东| 射洪县| 三台县| 夏河县| 灵石县| 招远市| 鲁山县| 黄陵县| 泸定县| 正安县| 聂荣县| 鄂伦春自治旗| 绍兴县| 绍兴县| 宁德市| 仁怀市| 宜阳县| 临颍县| 黄浦区| 古浪县| 称多县| 双鸭山市| 鹤壁市| 长治市| 老河口市| 临洮县| 安多县| 祥云县| 贵德县| 阳高县| 涿州市| 罗田县| 确山县| 蓝田县| 桓台县|