电脑知识|欧美黑人一区二区三区|软件|欧美黑人一级爽快片淫片高清|系统|欧美黑人狂野猛交老妇|数据库|服务器|编程开发|网络运营|知识问答|技术教程文章 - 好吧啦网

您的位置:首頁技術(shù)文章
文章詳情頁

springboot+VUE實現(xiàn)登錄注冊

瀏覽:4日期:2022-09-29 10:47:14

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

一、springBoot

創(chuàng)建springBoot項目

分為三個包,分別為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;@RestControllerpublic 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

package springbootmybatis.service;import org.springframework.stereotype.Service;import springbootmybatis.dao.UserMapper;import javax.annotation.Resource;@Servicepublic 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;@Datapublic class User { private String account; private String password;}

UserMapper.java

package springbootmybatis.dao;import org.apache.ibatis.annotations.Mapper;@Mapperpublic interface UserMapper { int register(String account, String password); int login(String account, String password);}

UserMapper.xml

<?xml version='1.0' encoding='UTF-8' ?><!DOCTYPE mapperPUBLIC '-//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 resultType='Integer'>select count(*) from User where account=#{account} and password=#{password}; </select></mapper>

主干配置

application.yaml

server.port: 8000spring: 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.Drivermybatis: 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項目

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

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

安裝VUE

npm i -g vue-cli

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

vue init webpack project

啟動項目

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

修改項目文件,按照如下結(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='請輸入帳號'></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

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

輸入賬號密碼,實現(xiàn)簡單的注冊,登錄功能。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 报警器_家用防盗报警器_烟雾报警器_燃气报警器_防盗报警系统厂家-深圳市刻锐智能科技有限公司 | 阳光模拟试验箱_高低温试验箱_高低温冲击试验箱_快速温变试验箱|东莞市赛思检测设备有限公司 | 喷播机厂家_二手喷播机租赁_水泥浆洒布机-河南青山绿水机电设备有限公司 | 电子万能试验机_液压拉力试验机_冲击疲劳试验机_材料试验机厂家-济南众标仪器设备有限公司 | 陕西视频监控,智能安防监控,安防系统-西安鑫安5A安防工程公司 | 预制直埋蒸汽保温管-直埋管道-聚氨酯发泡保温管厂家 - 唐山市吉祥保温工贸有限公司 | 上海新光明泵业制造有限公司-电动隔膜泵,气动隔膜泵,卧式|立式离心泵厂家 | 哔咔漫画网页版在线_下载入口访问指引 | 急救箱-应急箱-急救包厂家-北京红立方医疗设备有限公司 | 水厂自动化|污水处理中控系统|水利信息化|智慧水务|智慧农业-山东德艾自动化科技有限公司 | 阁楼货架_阁楼平台_仓库仓储设备_重型货架_广州金铁牛货架厂 | 防勒索软件_数据防泄密_Trellix(原McAfee)核心代理商_Trellix(原Fireeye)售后-广州文智信息科技有限公司 | 洗瓶机厂家-酒瓶玻璃瓶冲瓶机-瓶子烘干机-封口旋盖压盖打塞机_青州惠联灌装机械 | 上海乾拓贸易有限公司-日本SMC电磁阀_德国FESTO电磁阀_德国FESTO气缸 | 电脑刺绣_绣花厂家_绣花章仔_织唛厂家-[源欣刺绣]潮牌刺绣打版定制绣花加工厂家 | 货车视频监控,油管家,货车油管家-淄博世纪锐行电子科技 | 焊管生产线_焊管机组_轧辊模具_焊管设备_焊管设备厂家_石家庄翔昱机械 | 粉末冶金注射成型厂家|MIM厂家|粉末冶金齿轮|MIM零件-深圳市新泰兴精密科技 | 标准品网_标准品信息网_【中检计量】 | 撕碎机,撕破机,双轴破碎机-大件垃圾破碎机厂家 | 附着力促进剂-尼龙处理剂-PP处理剂-金属附着力处理剂-东莞市炅盛塑胶科技有限公司 | 水质监测站_水质在线分析仪_水质自动监测系统_多参数水质在线监测仪_水质传感器-山东万象环境科技有限公司 | 蓝鹏测控平台 - 智慧车间系统 - 车间生产数据采集与分析系统 | 美的商用净水器_美的直饮机_一级代理经销商_Midea租赁价格-厂家反渗透滤芯-直饮水批发品牌售后 | 金属雕花板_厂家直销_价格低-山东慧诚建筑材料有限公司 | 中空玻璃生产线,玻璃加工设备,全自动封胶线,铝条折弯机,双组份打胶机,丁基胶/卧式/立式全自动涂布机,玻璃设备-山东昌盛数控设备有限公司 | 耙式干燥机_真空耙式干燥机厂家-无锡鹏茂化工装备有限公司 | 隐形纱窗|防护纱窗|金刚网防盗纱窗|韦柏纱窗|上海青木装潢制品有限公司|纱窗国标起草单位 | 螺旋丝杆升降机-SWL蜗轮-滚珠丝杆升降机厂家-山东明泰传动机械有限公司 | 电缆接头-防爆电缆接头-格兰头-金属电缆接头-防爆填料函 | Safety light curtain|Belt Sway Switches|Pull Rope Switch|ultrasonic flaw detector-Shandong Zhuoxin Machinery Co., Ltd | DWS物流设备_扫码称重量方一体机_快递包裹分拣机_广东高臻智能装备有限公司 | 成都软件开发_OA|ERP|CRM|管理系统定制开发_成都码邻蜀科技 | 讲师宝经纪-专业培训机构师资供应商_培训机构找讲师、培训师、讲师经纪就上讲师宝经纪 | 二维运动混料机,加热型混料机,干粉混料机-南京腾阳干燥设备厂 | 光照全温振荡器(智能型)-恒隆仪器 | 苏州防水公司_厂房屋面外墙防水_地下室卫生间防水堵漏-苏州伊诺尔防水工程有限公司 | 西子馋火锅鸡加盟-太原市龙城酉鼎餐饮管理有限公司 | 超声骨密度仪,双能X射线骨密度仪【起草单位】,骨密度检测仪厂家 - 品源医疗(江苏)有限公司 | 烟台游艇培训,威海游艇培训-烟台市邮轮游艇行业协会 | 在线PH计-氧化锆分析仪-在线浊度仪-在线溶氧仪- 无锡朝达 |