国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

微信小程序登錄頁驗(yàn)證與頁面跳轉(zhuǎn)(二) ---結(jié)合SpringBoot和MySQL實(shí)現(xiàn)多用戶登錄

這篇具有很好參考價(jià)值的文章主要介紹了微信小程序登錄頁驗(yàn)證與頁面跳轉(zhuǎn)(二) ---結(jié)合SpringBoot和MySQL實(shí)現(xiàn)多用戶登錄。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。


一、開發(fā)環(huán)境

Spring Boot的開發(fā)環(huán)境如下:
1、IDEA:2020
2、JDK版本:1.8
3、MySQL 版本:8

二、搭建Spring Boot項(xiàng)目

1.創(chuàng)建項(xiàng)目

代碼如下(示例):

打開IDEA,新建項(xiàng)目:
微信小程序+spring+mysql實(shí)現(xiàn)登錄注冊,SpringBoot,微信小程序,spring boot,微信小程序,mysql

這里選擇Spring lnitializr:
微信小程序+spring+mysql實(shí)現(xiàn)登錄注冊,SpringBoot,微信小程序,spring boot,微信小程序,mysql
在接下來的頁面中進(jìn)行如下配置:
微信小程序+spring+mysql實(shí)現(xiàn)登錄注冊,SpringBoot,微信小程序,spring boot,微信小程序,mysql
進(jìn)行下一步:選擇SpringBoot的版本,這里選擇的是2.7.14
微信小程序+spring+mysql實(shí)現(xiàn)登錄注冊,SpringBoot,微信小程序,spring boot,微信小程序,mysql然后:
微信小程序+spring+mysql實(shí)現(xiàn)登錄注冊,SpringBoot,微信小程序,spring boot,微信小程序,mysql
設(shè)置項(xiàng)目所在路徑和設(shè)置項(xiàng)目名稱:
微信小程序+spring+mysql實(shí)現(xiàn)登錄注冊,SpringBoot,微信小程序,spring boot,微信小程序,mysql
項(xiàng)目創(chuàng)建好后,打開pom.xml,引入依賴,添加位置是在depedencies標(biāo)簽中。
微信小程序+spring+mysql實(shí)現(xiàn)登錄注冊,SpringBoot,微信小程序,spring boot,微信小程序,mysql

	<!--Spring Boot web依賴-->
	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-web</artifactId>
	</dependency>
	
	<!-- mybatis-plus框架 -->
	<dependency>
		<groupId>com.baomidou</groupId>
		<artifactId>mybatis-plus-boot-starter</artifactId>
		<version>3.5.2</version>
	</dependency>
	<!--mysql數(shù)據(jù)庫庫-->
	<dependency>
		<groupId>mysql</groupId>
		<artifactId>mysql-connector-java</artifactId>
		<version>8.0.26</version>
	</dependency>
	<!--德魯伊-->
	<dependency>
		<groupId>com.alibaba</groupId>
		<artifactId>druid-spring-boot-starter</artifactId>
		<version>1.1.17</version>
	</dependency>

注:
如果這里報(bào)錯(cuò),把2.1.14之后的.release去掉
微信小程序+spring+mysql實(shí)現(xiàn)登錄注冊,SpringBoot,微信小程序,spring boot,微信小程序,mysql

導(dǎo)入依賴后,在根目錄下創(chuàng)建controller文件夾,在其中新建LoginController,在其中書寫如下代碼:

@RestController
public class LoginController {

    @Autowired
    UserService userService;

    @PostMapping("login")
    public Result login(@RequestBody User user){
        System.out.println(user);
        User loginUser = userService.login(user);
        System.out.println(loginUser);
        if(loginUser == null){
            return new Result(201,"用戶名或密碼錯(cuò)誤",loginUser);
        }
        return new Result(200,"登錄成功",loginUser);
    }
}

新建entity文件夾,新建User實(shí)體類:

@Data
@ToString
public class User {
    private String username;
    private String password;
}

新建mapper文件夾,新建UserDao接口

@Repository
public interface UserDao {
    @Select("select * from user where username = #{username} and password = #{password}")
    User login(User user);
}

新建servie文件夾,創(chuàng)建UserService和它的實(shí)現(xiàn)類:

public interface UserService {
    User login(User user);
}
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserDao userDao;

    @Override
    public User login(User user) {
        User user1 = userDao.login(user);
        return user1;
    }
}

新建utils文件夾,在其中新建Result響應(yīng)體:

@Data
@ToString
public class Result {
    private Integer code;
    private String msg;
    private Object data;

    public Result(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Result(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }
}

最后,在application.yml文件中加入以下配置:

spring:
    datasource:
        driver-class-name: com.mysql.cj.jdbc.Driver
        url: jdbc:mysql://127.0.0.1:3306/wechat?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
        username: root
        password: 123456
        type: com.alibaba.druid.pool.DruidDataSource
server:
    port: 8080

最終項(xiàng)目結(jié)構(gòu)如下:
微信小程序+spring+mysql實(shí)現(xiàn)登錄注冊,SpringBoot,微信小程序,spring boot,微信小程序,mysql

2.創(chuàng)建數(shù)據(jù)庫

我使用的軟件是Navicate,創(chuàng)建名為wechat的數(shù)據(jù)庫,編碼格式選擇utf-8。
微信小程序+spring+mysql實(shí)現(xiàn)登錄注冊,SpringBoot,微信小程序,spring boot,微信小程序,mysql
數(shù)據(jù)庫設(shè)計(jì)如下,命名為user.
微信小程序+spring+mysql實(shí)現(xiàn)登錄注冊,SpringBoot,微信小程序,spring boot,微信小程序,mysql
創(chuàng)建好數(shù)據(jù)庫后,在其中添加數(shù)據(jù)如下:

微信小程序+spring+mysql實(shí)現(xiàn)登錄注冊,SpringBoot,微信小程序,spring boot,微信小程序,mysql
在數(shù)據(jù)庫中添加其他數(shù)據(jù)即可實(shí)現(xiàn)多賬戶登錄。

后端和數(shù)據(jù)庫準(zhǔn)備完成后,點(diǎn)擊如下按鈕運(yùn)行項(xiàng)目:
微信小程序+spring+mysql實(shí)現(xiàn)登錄注冊,SpringBoot,微信小程序,spring boot,微信小程序,mysql
看到如下結(jié)果說明項(xiàng)目在8080端口啟動(dòng)成功:
微信小程序+spring+mysql實(shí)現(xiàn)登錄注冊,SpringBoot,微信小程序,spring boot,微信小程序,mysql
打開postman進(jìn)行測試,測試端口設(shè)置為localhost:8080/login,下圖顯示測試成功。
微信小程序+spring+mysql實(shí)現(xiàn)登錄注冊,SpringBoot,微信小程序,spring boot,微信小程序,mysql

三、微信小程序端

端口測試成功后,打開微信小程序,更改之前的HTML和JS代碼(見本人主頁前文),和CSS不用作任何更改

1、HTML代碼:

<view class="welcome">
<p>歡迎使用智能門禁系統(tǒng)</p>
</view>

<view class='login_block' >
  <view><span class="iconfont icon-geren"></span><input type='text' placeholder="請輸入宿舍號(hào)" bindinput='inputUsr' class='input' value="{{ username }}"
    model:value="{{ username }}"></input></view>
  <view><span class="iconfont icon-mima1"></span><input password='true' placeholder="請輸入通行密碼" bindinput='inputPwd'class='input'value="{{ password }}"
    model:value="{{ password }}"></input></view>
  <button type='primary' bindtap='login' class="confirm">確定</button>
</view>

2、JavaScript代碼:

// pages/login/index.js
Page({

  /**
   * 頁面的初始數(shù)據(jù)
   */
  data: {
    password_input: "",
    username: "admin",
    password: "123456"
  },
  login: function () {
    if (this.data.username == "" || this.data.password == "") {
      wx.showToast({
        title: '請輸入宿舍號(hào)和密碼',
        icon: 'none',
        duration: 2000
      })
    } else {
      wx.request({
        url: 'http://localhost:8080/login',
        method: 'POST',
        data: {
          username: this.data.username,
          password: this.data.password
        },
        success: (res) => {
          console.log(res)
          if (res.data.code == 200) {
            wx.showToast({
              title: res.data.msg,
              icon: 'success',
              duration: 2000
            })
            setTimeout(function(){
              wx.navigateTo({
                url: '/pages/hello/hello',
              })
            },2000);
          } else {
            wx.showToast({
              title: res.data.msg,
              icon: 'none',
              duration: 2000
            })
            return;
          }
          wx.setStorage(
            {
              key: "username",
              data: this.data.username,
            }
            
          )
          wx.setStorage(
            {
              key: "password",
              data: this.data.password,
            }
          )
          
        }
      })
    }

  }
})

如果頁面時(shí)TabBar頁面,需要使用

wx.switchTab({
     url: '/pages/index/index',
})

完成后,測試結(jié)果:
微信小程序+spring+mysql實(shí)現(xiàn)登錄注冊,SpringBoot,微信小程序,spring boot,微信小程序,mysql
登錄成功后成功跳轉(zhuǎn)到index頁面:
微信小程序+spring+mysql實(shí)現(xiàn)登錄注冊,SpringBoot,微信小程序,spring boot,微信小程序,mysql

總結(jié)

以上便是Spring Boot+微信小程序+MySQL實(shí)現(xiàn)登錄功能與頁面跳轉(zhuǎn)的全部功能,這種實(shí)現(xiàn)方式較為簡陋,僅為學(xué)習(xí)使用,希望大家多多點(diǎn)贊支持。
遇到問題大家可以私聊我哦。文章來源地址http://www.zghlxwxcb.cn/news/detail-815740.html

到了這里,關(guān)于微信小程序登錄頁驗(yàn)證與頁面跳轉(zhuǎn)(二) ---結(jié)合SpringBoot和MySQL實(shí)現(xiàn)多用戶登錄的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 微信小程序頁面跳轉(zhuǎn)方式+跳轉(zhuǎn)小程序

    官方文檔:https://developers.weixin.qq.com/miniprogram/dev/api/route/wx.switchTab.html 跳轉(zhuǎn)到 tabBar 頁面,并關(guān)閉其他所有非 tabBar 頁面 跳轉(zhuǎn)到其他頁面(非tabBar頁) 返回上一頁面或返回多級(jí)頁面 首先需要在當(dāng)前小程序app.json中定義:需要跳轉(zhuǎn)的小程序的app-id app.josn文件: 第一種方法:wx.

    2024年02月12日
    瀏覽(229)
  • 微信小程序之頁面跳轉(zhuǎn)

    1、wx.navigateTo( ): 功能:保留當(dāng)前頁面,跳轉(zhuǎn)到應(yīng)用內(nèi)的某個(gè)頁面。 特點(diǎn):跳轉(zhuǎn)后原頁面保留在后臺(tái),可以通過 wx.navigateBack() 返回到原頁面,新頁面顯示在原頁面之上,有返回按鈕。 2、wx.redirectTo( ): 功能:關(guān)閉當(dāng)前頁面,跳轉(zhuǎn)到應(yīng)用內(nèi)的另一個(gè)頁面。 特點(diǎn):跳轉(zhuǎn)后原頁面

    2024年04月23日
    瀏覽(18)
  • 微信小程序(四)頁面跳轉(zhuǎn)

    微信小程序(四)頁面跳轉(zhuǎn)

    注釋很詳細(xì),直接上代碼 上一篇 新增內(nèi)容 1.相對(duì)路徑頁面跳轉(zhuǎn) 2. 絕對(duì)路徑頁面跳轉(zhuǎn) index.wxml 效果演示: 跳轉(zhuǎn)之后 下一篇

    2024年01月19日
    瀏覽(22)
  • 微信小程序頁面跳轉(zhuǎn)方法

    微信小程序頁面跳轉(zhuǎn)的各種方法總結(jié),備查。 保留當(dāng)前頁面,跳轉(zhuǎn)到應(yīng)用內(nèi)的某個(gè)頁面。可以通過調(diào)用 wx.navigateBack 返回到原頁面。跳轉(zhuǎn)后左上角出現(xiàn)返回小箭頭,點(diǎn)擊后可返回原本頁面。示例代碼: 使用場景 適用于需要跳轉(zhuǎn)到新頁面并保留原頁面狀態(tài)的情況,比如從列表

    2024年02月04日
    瀏覽(26)
  • 微信小程序如何跳轉(zhuǎn)頁面

    微信小程序跳轉(zhuǎn)頁面可以通過 wx.navigateTo 函數(shù)來實(shí)現(xiàn)。具體步驟如下: 首先,在app.json文件中配置需要跳轉(zhuǎn)的目標(biāo)頁面,例如: 在原始頁面的js文件中,調(diào)用 wx.navigateTo 函數(shù),跳轉(zhuǎn)到目標(biāo)頁面,例如: 其中, url 參數(shù)指定要跳轉(zhuǎn)的目標(biāo)頁面路徑。 如果要在目標(biāo)頁面接收傳遞參

    2024年02月09日
    瀏覽(23)
  • 微信小程序點(diǎn)擊跳轉(zhuǎn)頁面

    微信小程序點(diǎn)擊跳轉(zhuǎn)頁面

    ? ? ?第一步:index.wxml 第二步:index.js 以下是點(diǎn)擊跳轉(zhuǎn)的詳情頁面: xiang.wxml: xiang.wxss:

    2024年02月14日
    瀏覽(17)
  • 微信小程序 跳轉(zhuǎn)客服頁面

    微信小程序 跳轉(zhuǎn)客服頁面

    小程序 用戶反饋 沒有頁面設(shè)計(jì) 可以直接跳轉(zhuǎn)小程序指定客服頁面

    2024年02月06日
    瀏覽(20)
  • 微信小程序—點(diǎn)擊實(shí)現(xiàn)頁面跳轉(zhuǎn)

    1.按鈕button標(biāo)簽通過bindtap屬性綁定點(diǎn)擊事件實(shí)現(xiàn)頁面跳轉(zhuǎn)。 2.但需注意,跳轉(zhuǎn)到tabBar頁面和非tabBar頁面所調(diào)用的函數(shù)方法不一樣。 跳轉(zhuǎn)到TabBar頁面需用wx.switchTab()方法 3.而 跳轉(zhuǎn)到非tabBar頁面用wx.navigateTo()方法

    2024年02月11日
    瀏覽(92)
  • 微信小程序事件和頁面跳轉(zhuǎn)

    微信小程序事件和頁面跳轉(zhuǎn)

    一、頁面跳轉(zhuǎn) 1.非TabBar頁面 一個(gè)小程序擁有多個(gè)頁面,我們通過wx.navigateTo進(jìn)入一個(gè)新的頁面 我們通過下邊點(diǎn)擊事件實(shí)現(xiàn)頁面跳轉(zhuǎn)進(jìn)行代碼實(shí)現(xiàn)及參考 wx.navigateBack()回退到上一個(gè)頁面 wx.redirectTo(url)刪除當(dāng)前頁面跳轉(zhuǎn)到指定頁面 2.TabBar頁面: wx.switchTab只能打開TabBar 3.其他

    2023年04月09日
    瀏覽(22)
  • 微信小程序之普通頁面跳轉(zhuǎn)到tabBar頁面

    微信小程序之普通頁面跳轉(zhuǎn)到tabBar頁面

    前言 最近在做一個(gè)投稿小程序,主要功能是作者可以在微信小程序登錄,注冊,然后登陸進(jìn)入主頁面,可以投遞稿件以及瀏覽自己已投遞的稿件,和個(gè)人中心等主要功能,做的比較簡單,因?yàn)楸救藢?duì)于小程序是一個(gè)初學(xué)者。 遇到的問題 登錄頁面不是tabBar頁面,只是一個(gè)普通

    2024年02月08日
    瀏覽(36)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包