Spring Boot 整合微信小程序实现登录与增删改查

超级详细的微信小程序登录基于SpringBoot 此篇文章,针对的是很多看不懂微信官方文档,或者是刚入门小程序和java开发的开发者,教程也会非常详细的讲到我在实现这个功能时碰到的误区,以及详细的介绍整个流程。在小程序库2.10.4之前,我们利用小程序进行登录时,不做商业处理的情况下,利用java对用户进行处理,我们需要使用到小程序的两个API。实际上用到了三个API,看自己的需求选择。提示:以下是本篇文章正文内容,下面案例可供参考此次教程是针对于还未更新的方法,教程非常详细,希望能够帮助到你。 阅读详情

作者:浮云骑士LIN

cnblogs.com/ckfeng/p/12812214.html


项目描述:在微信小程序中通过与Springboot操作数据库实现简单的增删改查,其中我是用springboot整合mybatis-plus 和mysql使用的

1. 开发前准备

1.1 前置知识

  • java基础

  • SpringBoot简单基础知识

1.2 环境参数

  • 开发工具:IDEA

  • 基础环境:Maven+JDK8

  • 主要技术:SpringBoot、lombok、mybatis-plus、mysql 、微信小程序

  • SpringBoot版本:2.2.6

2.开发者服务器

项目结构:

2.1 初始配置

(1)pom.xml配置

 <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.1</version>
        </dependency>

        <!--模板引擎-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

        <!-- 引入阿里数据库连接池 -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.1.14</version>
        </dependency>

        <!-- mysql依赖-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.42</version>
            <scope>runtime</scope>
        </dependency>

        <!-- mybatisPlus 核心库 -->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.1.0</version>
        </dependency>

        <!--生成实体成get set-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>

        <!-- pagehelper 分页插件 -->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.2.5</version>
        </dependency>

        <!--junit 测试-->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

(2)application.yml

# Spring Boot 的数据源配置
spring:
  datasource:
    name: wx
    url: jdbc:mysql://localhost:3306/wx_mini_program?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
 username: root
    password: root
    # 使用druid数据源
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.jdbc.Driver
    filters: stat
    maxActive: 20 initialSize: 1 maxWait: 60000 minIdle: 1 timeBetweenEvictionRunsMillis: 60000 minEvictableIdleTimeMillis: 300000 validationQuery: select 'x' testWhileIdle: true testOnBorrow: false testOnReturn: false poolPreparedStatements: true maxPoolPreparedStatementPerConnectionSize: 20 maxOpenPreparedStatements: 20 # mybatis-plus相关配置
mybatis-plus:
  # xml扫描,多个目录用逗号或者分号分隔(告诉 Mapper 所对应的 XML 文件位置)
  mapper-locations: classpath:mapper/*.xml
  # 以下配置均有默认值,可以不设置
  global-config:
    db-config:
      #主键类型 AUTO:"数据库ID自增" INPUT:"用户输入ID",ID_WORKER:"全局唯一ID (数字类型唯一ID)", UUID:"全局唯一ID UUID";
      id-type: auto
      #字段策略 IGNORED:"忽略判断"  NOT_NULL:"非 NULL 判断")  NOT_EMPTY:"非空判断"
      field-strategy: NOT_EMPTY
      #数据库类型
      db-type: MYSQL

  # 指定实体类的包
  type-aliases-package: com.ckf.login_wx.entity
  configuration:
    # 是否开启自动驼峰命名规则映射:从数据库列名到Java属性驼峰命名的类似映射
    map-underscore-to-camel-case: true
    # 如果查询结果中包含空值的列,则 MyBatis 在映射的时候,不会映射这个字段
    call-setters-on-nulls: true
    # 这个配置会将执行的sql打印出来,在开发或测试的时候可以用
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

# PageHelper分页插件
pagehelper:
  helperDialect: mysql
  reasonable: true
  supportMethodsArguments: true
  params: count=countSql

2.2 小程序用户表


CREATE table users(
 id int not null PRIMARY key auto_increment,
 name varchar(255) not null,
 age int not null );

insert into users value(null,'陈克锋',18);
insert into users value(null,'陈克帅',11);
insert into users value(null,'陈克兵',14); select * from users;

2.3 pojo

2.4 mapper

2.5 service

2.5 serviceImpl

配置SpringBoot扫描mapper

2.6 controller

LoginController


package com.ckf.login_wx.controller;

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

import java.util.HashMap;
import java.util.Map; /**
 * @author 安详的苦丁茶
 * @date 2020/4/30 11:46 */ @RestController public class LoginController { /**
     * 登录
     * @param phone
     * @param password
     * @return */ @PostMapping("/doLogin") public Map doLogin(String phone, String password){
        Map map = new HashMap(); if ((phone.equals("10086")&& password.equals("123456"))){
            map.put("code",200);
            map.put("result","登录成功");
            System.out.println("登录成功");
        }else {
            map.put("result","no");
        } return map;
    }

}

UserController


package com.ckf.login_wx.controller;

import com.ckf.login_wx.entity.User;
import com.ckf.login_wx.servic.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; /**
 * @author 安详的苦丁茶
 * @date 2020/4/30 13:39 */ @RestController
@RequestMapping("/test") public class UserController {

    @Autowired private UserService userService; /**
     * 查询全部
     * @return */ @GetMapping("/list") public Object list(){
        System.out.println("查询成功"); return userService.list();
    } /**
     * 根据id删除
     * @param id
     * @return */ @GetMapping("/delete") public boolean delete(Integer id){
        System.out.println("删除成功"); return userService.removeById(id);
    } /**
     *  根据id查询
      * @param id
     * @return */ @GetMapping("/byid") public Object byid(Integer id){
        System.out.println("查询成功"); return userService.getById(id);
    } /**
     *  修改
     * @param user
     * @return */ @PostMapping("/update") public boolean update(@RequestBody User user){
        System.out.println("修改成功"); return userService.updateById(user);
    } /**
     * 添加
     * @param user
     * @return */ @PostMapping("/add") public boolean add(@RequestBody User user){
        System.out.println("添加成功"); return userService.save(user);
    }

}

3. 微信小程序

项目结构:

3.1 初始配置

3.2 bing.wxml


<!--pages/bind/bind.wxml-->
<view>

  <form bindsubmit='doLogin'>
            <!--账号-->
            <view class="inputView">

                <label class="loginLabel">账号</label>
                <input name="phone" value='10086' class="inputText" placeholder="请输入账号" />
            </view>
            <view class="line"></view>

            <!--密码-->
            <view class="inputView">

                <label class="loginLabel">密码</label>
                <input name="password" value='123456' class="inputText" password="true" placeholder="请输入密码" />
            </view>
            <view class="line"></view>
            <!--按钮-->
            <view class='backColor'>
                <button class="loginBtn" formType="submit"  open-type='getUserInfo' >登录</button>
            </view>

            <!-- <view>
                <button class="goRegistBtn" type="warn" open-type='getUserInfo' bindgetuserinfo='doLogin'>微信登录</button>
            </view> -->
        </form>

</view>

3.3 bing.js

3.3 list.wxml


<!--pages/list/list.wxml-->
  <button class="add" type='primary' bindtap='addArea'>添加</button>
<view class="container">
  <view class='widget'>
    <text class='column'>编号</text>
    <text class='column'>姓名</text>
    <text class='column'>年龄</text>
    <text class='link-column'>操作</text>
  </view>
  <scroll-view scroll-y="true">
    <view>
      <block wx:for='{{list}}'>
      <view class='widget'> 
        <text class='column'>{{item.id}}</text>
        <text class='column'>{{item.name}}</text>
         <text class='column'>{{item.age}}</text>
        <view class='link-column'>
          <navigator class='link' url='../operation/operation?id={{item.id}}'>编辑</navigator> |
          <text class='link' bindtap='deleteArea' data-areaid='{{item.id}}' data-areaname='{{item.name}}' data-index='{{index}}'>删除</text>  
        </view>
        </view>      
      </block>
    </view>
  </scroll-view>

</view>

3.4 list.js


// pages/list/list.js
Page({ /**
   * 页面的初始数据 */ data: {
    list:[]
  }, /**
   * 生命周期函数--监听页面加载 */ onLoad: function (options) {

  }, /**
   * 生命周期函数--监听页面初次渲染完成 */ onReady: function () {

  }, /**
   * 生命周期函数--监听页面显示 */ onShow: function () { var that=this;
    wx.request({
      url: 'http://localhost:8080/test/list',
      method:'GET',
      data:{},
      success:function(res){ var list=res.data; if(list==null){ var toastText='获取数据失败';
          wx.showToast({
            title: toastText,
            icon:'',
            duration:2000 //弹出时间
 })
        }else{
          that.setData({
            list:list
          })
        }
      }
    })
  }, /**
   * 生命周期函数--监听页面隐藏 */ onHide: function () {

  }, /**
   * 生命周期函数--监听页面卸载 */ onUnload: function () {

  }, /**
   * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () {

  }, /**
   * 页面上拉触底事件的处理函数 */ onReachBottom: function () {

  }, /**
   * 用户点击右上角分享 */ onShareAppMessage: function () {

  },
  addArea:function(){
    wx.navigateTo({
      url:'../operation/operation' })
  },
  deleteArea: function (e) { var that=this;
    wx.showModal({
      title: '提示',
      content: '确定要删除[' + e.target.dataset.areaname +']吗?',
      success:function(sm){ if(sm.confirm){
          wx.request({
            url: 'http://localhost:8080/test/delete',
            data: { id: e.target.dataset.areaid},
            method:'GET',
            success:function(res){ var result=res.statusCode; var toastText="删除成功"; if(result!=200){
                toastText = "删除失败";
              }else{
                that.data.list.splice(e.target.dataset.index,1);
                that.setData({
                  list:that.data.list
                });
              }
              wx.showToast({
                title: toastText,
                icon:'',
                duration:2000 });
            }
          })
        }
      }
    })

  }
})

3.5 app.json


{ "pages": [ "pages/bind/bind", "pages/list/list", "pages/logs/logs", "pages/operation/operation", "pages/index/index" ], "window": { "backgroundColor": "#F6F6F6", "backgroundTextStyle": "light", "navigationBarBackgroundColor": "#29d", "navigationBarTitleText": "login", "navigationBarTextStyle": "black" }, "sitemapLocation": "sitemap.json", "style": "v2" }

4. 测试

启动开发者服务器,启动SpringBoot的main方法。

打开微信小程序开发者工具

登录页面

首页

添加页面

修改页面

删除

到处基本的增删改查操作已经完成了

如有需要前往 Gitee(码云)下载

前台:https://gitee.com/ckfeng/applet_of_wechat.git

后台:https://gitee.com/ckfeng/wx_login.git


若依Springboot实现小程序登录 使用ruoyi-vue-plus实现小程序登录 阅读详情

相关推荐

微信小程序的授权登录-Java 后端 (Spring boot)

小程序登录Java spring boot

zlfjavahome的专栏 7752

如何使用微信小程序。

【代码】如何使用微信小程序。

weixin_46597615的博客 471

如何利用Spring Boot 整合微信小程序实现登录与增删改查(含代码解析)

项目描述: 在微信小程序中通过与Springboot操作数据库实现简单的增删改查,其中我是用springboot整合mybatis-plus 和mysql使用的. 1. 开发前准备 1.1 前置知识 java基础 SpringBoot简单基础知识 1.2 环境参数 开发工具:IDEA 基础环境:Maven+JDK8 主要技术:SpringBoot、lombok、mybatis-plus、mysql 、微信小程序 SpringBoot版本:2.2.6 2.开发者服务器 项目结构: 2.1 初始配置.

it小旭博客 993

Springboot实现微信小程序登录

/ 如果有私有声明,一定要先设置这个自己创建的私有的声明,这个是给builder的claim赋值,一旦写在标准的声明赋值之后,就是覆盖了那些标准的声明的。//商户API证书的证书序列号。//退款成功的回调地址。//支付成功的回调地址。// 指定签名的时候使用的签名算法,也就是header那部分。// 设置签名使用的签名算法和签名使用的秘钥。//小程序的appid。

A20001230T的博客 2818

内存学习(3):DRAM的基础存储结构(存储层级、读写过程,刷新与暂存)

DRAM,全称为 Dynamic Random Access Memory ,中文名是“动态随机存取存储器”。所谓“动态”是和“静态”相对应的,芯片世界里还有一种 SRAM 静态随机存取存储器的存在。笼统地说,DRAM 的结构比 SRAM 更简单,面积占用更小,适合制作大容量的存储芯片;而 SRAM 结构复杂一些,一般使用六个晶体管,面积消耗大,但是读写速度快,而且因为 SRAM 只用到晶体管,所以在工艺上和逻辑芯片相兼容,我们可以在逻辑芯片上直接集成 SRAM。

呆呆象呆呆的博客 2万+

数字IC后端PPA优化实战:Innovus中Timing一致性策略与Module Region布局技巧

本文深入探讨了数字IC后端设计中PPA优化的核心挑战,重点解析了Innovus与PrimeTime之间Timing不一致的根本原因。通过实战案例,详细介绍了在Innovus中设置Timing Margin、Derate以及RC Scale Factor等关键策略,以校准时序视图。同时,文章分享了利用Module Region进行物理布局规划的技巧,将关键模块约束在最优区域,并结合Group Path等进阶方法,有效提升时序收敛效率与PPA结果的可预测性。

f9g0h的博客 2690

springboot 微信pc扫码登录_手把手教你Spring Boot 整合微信小程序实现登录与增删改查...

知道的越多,不知道的就越多,业余的像一棵小草!编辑:业余草来源:https://www.xttblog.com/?p=4998项目描述:在微信小程序中通过与Springboot操作数据库实现简单的增删改查,其中我是用springboot整合mybatis-plus 和mysql使用的1. 开发前准备1.1 前置知识java基础SpringBoot简单基础知识1.2 环境参数开发工具:ID...

weixin_39650756的博客 858

BambuStudio学习笔记:GCode 类

关键成员解析 核心配置组件 状态跟踪系统 功能模块集成 核心方法剖析 主输出管道 实现多阶段处理: 分层处理流程: 实现智能路径规划: 关键特性: 实现模板故障检测: 采用三级流水线: 支持扩展类型: 实现多通道输出: 采用: 实现: 支持: 支持模块化编译: 典型流程: 实现功能:

zzzkk2009的专栏 938

手把手教你Spring Boot 整合微信小程序实现登录与增删改查

知道的越多,不知道的就越多,业余的像一棵小草!编辑:业余草来源:https://www.xttblog.com/?p=4998项目描述:在微信小程序中通过与Springboot操作数据库...

xmt1139057136的专栏 2467

Ubuntu 24.04 搭建 Squid 代理服务器终极指南:从入门到 HTTPS 缓存AI模型

本文详细指导在Ubuntu 24.04系统部署Squid代理服务器,实现AI大模型文件的高效缓存。重点内容包括:1) 安装squid及必备的squid-openssl扩展包;2) 配置HTTPS拦截(SSL-Bumping)功能,创建CA证书和SSL数据库;3) 优化缓存策略,设置4TB存储空间并强制缓存常见大文件格式;4) 结合华为防火墙实现透明代理。文章特别强调实际部署中的关键注意事项和常见错误解决方案,如证书路径配置、权限设置等问题,帮助用户快速搭建企业级缓存代理服务。

zlt315的博客 1921

HX720/HX711 数据采集实战:从硬件配置到姿态解析(附源码详解)

本文详细解析了HX720/HX711数据采集传感器的硬件配置与姿态解析实战技巧,包括选型指南、电路设计避坑、抗干扰方案及源码实现。通过优化驱动代码和数据处理算法,提升采样率与精度,适用于动态称重和工业检测等场景。附源码详解,助力开发者快速掌握高精度数据采集技术。

weixin_30752699的博客 659

javaweb简单的登录增删改查系统_Spring Boot 整合微信小程序实现登录与增删改查

优质文章,及时送达项目描述:在微信小程序中通过与Springboot操作数据库实现简单的增删改查,其中我是用springboot整合mybatis-plus 和mysql使用的1. 开发前准备1.1 前置知识java基础SpringBoot简单基础知识1.2 环境参数开发工具:IDEA基础环境:Maven+JDK8主要技术:SpringBoot、lombok、mybatis-plus、mysql ...

weixin_39681621的博客 211

基于matlab的心电信号预处理

这是前段时间做的一个课程设计,做的比较简单,没有考虑到太细,只是初步地达到了想要的效果。这次设计主要是对心电信号进行预处理,将其信号中包含的一些干扰滤除或者抑制掉。 一、心电信号 (1)心电信号的特性   人体心电信号是非常微弱的生理低频电信号,通常最大的幅值不超过5mV,信号频率在0.05~100Hz之间。心电信号是通过安装在人体皮肤表面的电极来拾取的。由于电极和皮肤组织之间会发生极化现象

i_weimoli的博客 6万+
上一篇: 几乎涵盖你需要的SpringBoot所有操作|高清PDF
下一篇: 什么? 这40条显著提升Java性能的优化细节你竟然还不知道?!
Java思维导图
博客等级 码龄10年 306粉丝 71原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值