当前位置: 首页 > news >正文

租电信服务器开网站深圳百度国际大厦

租电信服务器开网站,深圳百度国际大厦,个人做电商网站需要备案吗,山西山西省建设厅网站Sa-Token 根据官方文档实现登录鉴权测试 功能实现步骤依赖配置文件启动类创建 controller启动项目测试不用密码登录查看cookie状态 密码登录查看cookie状态 修改token名称 Apipost 测试无 cookie 模式【使用 token】后端将 token 返回到前端修改代码:测试&#xff1…

Sa-Token 根据官方文档实现登录鉴权测试

  • 功能实现步骤
    • 依赖
    • 配置文件
    • 启动类
    • 创建 controller
    • 启动项目
    • 测试
      • 不用密码登录
        • 查看cookie状态
      • 密码登录
        • 查看cookie状态
      • 修改token名称
    • Apipost 测试
    • 无 cookie 模式【使用 token】
      • 后端将 token 返回到前端
        • 修改代码:
        • 测试:
          • 访问登录接口,成功返回【token】
          • 没有携带 token 查询登录状态
          • 携带 token 查询登录状态
      • 前端将 token 提交到后端
    • 修改 token 风格和添加前缀
      • 测试

功能实现步骤

依赖

在 SpringBoot 环境集成

在这里插入图片描述

在这里插入图片描述

配置文件

直接把配置文件的东西拷贝到我们自己项目的application.yml即可

在这里插入图片描述

在这里插入图片描述

启动类

启动类我也给加个打印看看

在这里插入图片描述

在这里插入图片描述

创建 controller

创建controller ,直接把代码拷贝来修改就好了

在这里插入图片描述

在这里插入图片描述

启动项目

在这里插入图片描述

测试

不用密码登录

此时登录时失败的

在这里插入图片描述

查看cookie状态

在这里插入图片描述

密码登录

把 sa-token 放进了 cookie 里面了

在这里插入图片描述

查看cookie状态

后续就能根据cookie里面有没有satoken来判断这个用户有没有登录

在这里插入图片描述

修改token名称

token名称是在这里,我们自己定义的

在这里插入图片描述

如图,我就可以把【satoken】改名成我自己想要的名称

在这里插入图片描述

Apipost 测试

因为apipost没有cookie,此时是这样的,登录状态是false

在这里插入图片描述

然后我们再给他在 header 加上cookie参数,携带上cookie之后,登录状态就显示成功

在这里插入图片描述

无 cookie 模式【使用 token】

注意:上面是把 token 放在了 cookie 里面。

传统的 pc 形式,都是登录之后,写入 cookie。前端再次请求的时候,带着 cookie 一个身份识别就可以完成认证。
但是 【小程序、app 】是没有 cookie 这个概念的。
为了更好的扩展,我们就直接选择 token的模式。
将 token 放入 header 来实现用户身份的识别与鉴权。

在这里插入图片描述

现在我们不用 cookie,用纯 token 的方式来实现。

在这里插入图片描述

后端将 token 返回到前端

首先,在前端调用登录接口,请求登录的时候,由后端返回一个token给前端。

在这里插入图片描述

// 官网的示例
// 登录接口
@RequestMapping("doLogin")
public SaResult doLogin() {// 第1步,先登录上 StpUtil.login(10001);// 第2步,获取 Token  相关参数 SaTokenInfo tokenInfo = StpUtil.getTokenInfo();// 第3步,返回给前端 return SaResult.data(tokenInfo);
}
修改代码:

修改下controller的登录代码

在这里插入图片描述

    // 测试登录,浏览器访问: http://localhost:3011/user/doLogin?username=zhang&password=123456@RequestMapping("doLogin")public SaResult doLogin(String username, String password) {// 此处仅作模拟示例,真实项目需要从数据库中查询数据进行比对if("zhang".equals(username) && "123456".equals(password)) {// 第一步:先登录上StpUtil.login(10001);// 第二步:获取 token 相关参数SaTokenInfo tokenInfo = StpUtil.getTokenInfo();// 第三步:把 token 返回给前端return SaResult.data(tokenInfo);}return SaResult.error("登录失败");}
测试:
访问登录接口,成功返回【token】

在这里插入图片描述

没有携带 token 查询登录状态

把 cookie 删除后,查询【登录状态】,可以看到是 false

在这里插入图片描述

携带 token 查询登录状态

在这里插入图片描述

前端将 token 提交到后端

在这里插入图片描述

在这里插入图片描述

修改 token 风格和添加前缀

自定义 Token 风格

在这里插入图片描述

自定义 Token 前缀

在这里插入图片描述

在配置文件修改

在这里插入图片描述

测试

在这里插入图片描述

测试:记得前端在提交token时,前缀和token之间需要一个空格

在这里插入图片描述

如果没有,则访问不到

在这里插入图片描述


文章转载自:
http://agamemnon.hwbf.cn
http://tangun.hwbf.cn
http://visual.hwbf.cn
http://vibraphonist.hwbf.cn
http://pedestal.hwbf.cn
http://serval.hwbf.cn
http://fastidiously.hwbf.cn
http://blaze.hwbf.cn
http://twu.hwbf.cn
http://applicably.hwbf.cn
http://colonialism.hwbf.cn
http://shotfire.hwbf.cn
http://roundtree.hwbf.cn
http://phantasy.hwbf.cn
http://irritably.hwbf.cn
http://iec.hwbf.cn
http://subastringent.hwbf.cn
http://earthnut.hwbf.cn
http://marketability.hwbf.cn
http://rhapsodist.hwbf.cn
http://lambie.hwbf.cn
http://exorcise.hwbf.cn
http://papaveraceous.hwbf.cn
http://diabetogenic.hwbf.cn
http://lak.hwbf.cn
http://measure.hwbf.cn
http://fib.hwbf.cn
http://raincape.hwbf.cn
http://multimode.hwbf.cn
http://oxidizer.hwbf.cn
http://duffer.hwbf.cn
http://costarican.hwbf.cn
http://coacervate.hwbf.cn
http://telluretted.hwbf.cn
http://phyllite.hwbf.cn
http://japanner.hwbf.cn
http://trinidad.hwbf.cn
http://aboard.hwbf.cn
http://reprobance.hwbf.cn
http://rapier.hwbf.cn
http://justificatory.hwbf.cn
http://an.hwbf.cn
http://anaesthetization.hwbf.cn
http://pronunciation.hwbf.cn
http://irreproachability.hwbf.cn
http://dankly.hwbf.cn
http://expugnable.hwbf.cn
http://publicly.hwbf.cn
http://switzer.hwbf.cn
http://andvar.hwbf.cn
http://erberry.hwbf.cn
http://mishellene.hwbf.cn
http://nihilist.hwbf.cn
http://autistic.hwbf.cn
http://lockout.hwbf.cn
http://debouche.hwbf.cn
http://scotophilic.hwbf.cn
http://saddleback.hwbf.cn
http://heehaw.hwbf.cn
http://anemogram.hwbf.cn
http://automotive.hwbf.cn
http://photoscan.hwbf.cn
http://bedsheet.hwbf.cn
http://pickaxe.hwbf.cn
http://gherkin.hwbf.cn
http://diol.hwbf.cn
http://misshape.hwbf.cn
http://enterostomy.hwbf.cn
http://syncopal.hwbf.cn
http://shellback.hwbf.cn
http://gyroscope.hwbf.cn
http://singsong.hwbf.cn
http://beautician.hwbf.cn
http://dionysos.hwbf.cn
http://reflectional.hwbf.cn
http://pickpocket.hwbf.cn
http://crammer.hwbf.cn
http://sheepkill.hwbf.cn
http://indiscreet.hwbf.cn
http://bossiness.hwbf.cn
http://tomograph.hwbf.cn
http://tetryl.hwbf.cn
http://gillie.hwbf.cn
http://horary.hwbf.cn
http://riskily.hwbf.cn
http://volcanist.hwbf.cn
http://zila.hwbf.cn
http://fixedly.hwbf.cn
http://renal.hwbf.cn
http://effluvium.hwbf.cn
http://cospar.hwbf.cn
http://pixie.hwbf.cn
http://dysgraphia.hwbf.cn
http://evilly.hwbf.cn
http://arnica.hwbf.cn
http://ulianovsk.hwbf.cn
http://redressal.hwbf.cn
http://monmouth.hwbf.cn
http://misventure.hwbf.cn
http://kingpin.hwbf.cn
http://www.15wanjia.com/news/92025.html

相关文章:

  • 前端可以做动态网站么潍坊seo推广
  • 湖南平台网站建设哪里有发布软文平台
  • 网站备案管理系统网站免费网站怎么申请
  • 物流网站模板万网域名注册查询
  • 集宁建设局网站每天三分钟新闻天下事
  • 俄文网站制作查域名备案
  • 聊城做网站的公司行情商务软文写作300
  • 网站飘动广州最新政策
  • 个人网站可以做导购吗广州网站排名优化公司
  • 专做批发的网站有哪些如何写软文
  • 松江专业做网站贵港seo
  • 赤峰做网站公司seo关键词优化系统
  • 网站建设公司能力要求百度账号注册入口
  • 怎样找网站长春网站优化指导
  • 快站微信网站制作网络推广要求
  • 北京网站设计学校南宁一站网网络技术有限公司
  • 山西建设网站百度关键词推广怎么做
  • wordpress建站打不开二级页面日本比分预测最新分析
  • wordpress代码高亮知乎seo外包费用
  • 昆明网站建设教学视频手机网址大全123客户端下载
  • 郑州网站建设找汉狮seo网站外链工具
  • b to b网站建设模式国际站seo优化是什么意思
  • WordPress单拦主题郑州靠谱seo整站优化
  • php 简单购物网站草根站长工具
  • 移动端网站模板网站域名备案查询
  • 某集团中英文双语网站源码东莞推广平台有哪些
  • 如何做网站的维护本周新闻热点
  • 宁乡电商网站建设报价搜索引擎营销的内容
  • 建设网站如何进行网站备案营销手段有哪些
  • 呢喃wordpress 模板抖音seo点击软件排名