博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【java小程序实战】小程序注销功能实现
阅读量:4183 次
发布时间:2019-05-26

本文共 2528 字,大约阅读时间需要 8 分钟。

小程序实战中,如何实现程序的注销功能呢?后端代码只要删除用户的redi缓存即可。小程序端在成功返回消息后,进行登陆页面的跳转。

文章目录

页面展示

在这里插入图片描述

小程序的mine.wxml代码

mine.wxss代码

page {  font-size: 14px;}.container {   background-color: whitesmoke;   display: flex;   flex-direction: column;   align-items: center;}.container-row {   display: flex;   flex-direction: row;   margin-bottom: 10px;   margin-top: 10px;}.info-items {   margin-left: 30px;}.face {   width: 180rpx;   height: 180rpx;   border-radius: 50%;   margin-top: 20px;}.nickname {   margin-top: 5px;   font-weight: bold;   font-size: 18px;}.logout {  margin-top: 3px;  float: right;}.follow {   margin-top: 3px;}.line {   width: 100%;   height: 1px;   background-color: gainsboro;   margin-top: 1px;}.container-video {   display: flex;   flex-direction: row;   margin-top: 20px;   text-align: center;   border: solid 1px;   line-height: 30px;}.video-info {   width: 100%;}.video-info-selected {   background-color: gainsboro;}.container-video-list {   display: flex;   flex-direction: row;   flex-wrap: wrap;}.videoImage {   width: 250rpx;   height: 180px;}

注销事件的代码mine.js

通过事件函数发起请求,后端处理成功返回结果,并跳转至登陆页面。

设置小程序的全局变量userInfo为null

//注销事件    logout: function () {      console.log("logout")      var user = app.userInfo;      var serverUrl = app.serverUrl;      wx.showLoading({        title: '请等待',      });      wx.request({        url: serverUrl+'/logout?userId=' + user.id,        method:"POST",        header: {          'content-type': 'application/json' //默认值        },        success: function (res) {           wx.hideLoading();           if( res.data.status == 200){             wx.showToast({               title: '注销成功',               icon: 'success',               duration: 20000             });             //注销成功,设置全局信息为null             app.userInfo = null;             wx.navigateTo({               url: '../login/login',             })           }        }      })    },

RegistLoginController 中注销代码

根据用户id,清楚redis中的缓存记录。

@ApiOperation(value="用户注销" , notes = "用户注销的接口")    @ApiImplicitParam(name = "userId", value = "用户id" ,required = true,                      dataType = "String", paramType = "query")    @PostMapping("/logout")    public IMoocJSONResult logout(String userId) {        System.out.println("userId:"+userId);          redis.del(USER_REDIS_SESSION + ":" + userId);           return IMoocJSONResult.ok();    }

转载地址:http://ijfoi.baihongyu.com/

你可能感兴趣的文章
MapReduce Tez Storm Spark四个框架的异同
查看>>
kudu存储引擎
查看>>
PHP语法1
查看>>
Linux如何查看端口状态
查看>>
Guava cache 缓存
查看>>
UUID.randomUUID()是什么
查看>>
TimeUnit是什么
查看>>
2017年大数据的变化趋势
查看>>
作业、任务、进程、线程的区别
查看>>
laypage分页
查看>>
ojdbc14.jar 与ojdbc6.jar的区别
查看>>
如何区分Oracle的数据库,实例,服务名,SID
查看>>
怎样使用sqlplus连接oracle11g数据库
查看>>
JDBC连接数据库
查看>>
java日志组件介绍(common-logging,log4j,slf4j,logback )
查看>>
java运行jar命令提示没有主清单属性
查看>>
使用Maven为一个项目生成多个Jar包,将一个目录打成jar包
查看>>
CMD命令名详细大全
查看>>
C、C++、MATLAB、Python、Go 哪个比较适合写算法
查看>>
Spring的一个命名空间的名称空间处理程序没有找到
查看>>