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

电商网站设计公司皆选亿企邦/谷歌关键词分析工具

电商网站设计公司皆选亿企邦,谷歌关键词分析工具,制作微信网站模板下载不了,公司网站备案查询随着前端框架的不断发展,越来越多的项目更喜欢用前段后分离来做,作为后台人员,完全不想写一点前端,只想关注API的编写就够了 哈哈 但前后端分离开发项目还是会踩到太多坑,最近就有一个需求是,多个站点共享…

随着前端框架的不断发展,越来越多的项目更喜欢用前段后分离来做,作为后台人员,完全不想写一点前端,只想关注API的编写就够了 哈哈

但前后端分离开发项目还是会踩到太多坑,最近就有一个需求是,多个站点共享用户登录信息,就是当用户在某一个站点登录了,当点击到另一个项目的站点时,延用之前的登录信息,无需再次登录。 此时就想到了 使用Redis来实现该需求,当用户登录成功后,将用户信息保存到Redis,以sessionId为key json格式的用户信息为value。
这样做 那就有一个要求,那就是必须保持每次请求的sessionId必须一致。
前端使用的是vue2.0 后台使用的是java springboot

这里写图片描述

  • 首先我们解决跨域问题
@Configuration
public class CorsConfig {private CorsConfiguration buildConfig() {CorsConfiguration corsConfiguration = new CorsConfiguration();corsConfiguration.addAllowedOrigin("*");corsConfiguration.addAllowedHeader("*");corsConfiguration.addAllowedMethod("*");corsConfiguration.setAllowCredentials(true);return corsConfiguration;}@Beanpublic FilterRegistrationBean corsFilter() {UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();source.registerCorsConfiguration("/**", buildConfig());FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));bean.setOrder(Ordered.HIGHEST_PRECEDENCE);return bean;}
}
  • 然后写好controller代码
 @RequestMapping(value = "index1")public String index1(String num) {RespInfo respInfo = new RespInfo();respInfo.setCode(20);Map<String,String> map = new HashMap<String, String>();map.put("num",num);map.put("path",request.getRequestURI());map.put("sessionid",session.getId());respInfo.setData(map);System.out.println(JSON.toJSONString(map));return JSON.toJSONString(respInfo);}/*** 请求接口2* @param num* @return*/@RequestMapping(value = "index2")public String index2(String num){RespInfo respInfo = new RespInfo();respInfo.setCode(20);Map<String,String> map = new HashMap<String, String>();map.put("num",num);map.put("path",request.getRequestURI());map.put("sessionid",session.getId());respInfo.setData(map);System.out.println(JSON.toJSONString(map));return JSON.toJSONString(respInfo);}/*** 请求接口3* @param num* @return*/@RequestMapping(value = "index3")public String index3(String num){RespInfo respInfo = new RespInfo();respInfo.setCode(20);Map<String,String> map = new HashMap<String, String>();map.put("num",num);map.put("path",request.getRequestURI());map.put("sessionid",session.getId());respInfo.setData(map);System.out.println(JSON.toJSONString(map));return JSON.toJSONString(respInfo);}

关键 在main.js下面加上这句代码

axios.defaults.withCredentials = true

  • 我们看前端页面的代码
<template><div><h2>前后端分离SessionId共享(Java + Vue)</h2><Card><div v-for="obj in sessionids"><span>第{{ obj.num}}次访问</span><span style="color: red">{{ obj.path }}</span><span>SessionId:<b>{{ obj.sessionid }}</b></span></div></Card></div>
</template>
<script>import http from './http'export default {data () {return {sessionids: []}},created() {this.getSessionId(1)},methods: {getSessionId: function (number) {let timer = setInterval(() => {http.get('index1',{num: number}).then((res)=> {if (res) {console.log(res.data)this.sessionids.push(res.data)}})http.get('index2',{num: number}).then((res)=> {if (res) {console.log(res.data)this.sessionids.push(res.data)}})http.get('index3',{num: number}).then((res)=> {if (res) {console.log(res.data)this.sessionids.push(res.data)}})if (number >= 5) {clearInterval(timer)}number++},2000);}}}
</script>

源代码地址:https://github.com/niezhiliang/multy-domain-user-identifying

http://www.jmfq.cn/news/4931533.html

相关文章:

  • 邵阳seo快速排名/路由优化大师
  • app网站建设/2022年十大网络流行语发布
  • 做网站云服务器装系统/什么是精准营销
  • 网站建设收费价格/最新热搜新闻
  • 企业网站模板下载滚动网站模板/百度提问登陆入口
  • 宁波网络推广优化/seo优化方案模板
  • 用几个域名做网站好/网络营销方法有哪些?
  • 郑州网站建设选智巢/郑州网络推广专业公司
  • 工业设计在线网站/网络营销模式
  • 威海专业网站建设/百度安装下载
  • 尼乐清网站建设/种子搜索在线 引擎
  • 多语言版本网站/怎么做推广比较成功
  • 私人网站设计公司公司/北京网站优化外包
  • 一级a做囗爰片免费网站/邵阳seo排名
  • 江苏金安建设公司网站/营销推广计划怎么写
  • 临清住房建设网站/广告点击一次多少钱
  • 如何建立公司网址/山西搜索引擎优化
  • 网站建设帮助中心/百度上看了不健康的内容犯法吗
  • 怎么做html网站/拼多多seo是什么意思
  • 网页设计制作要求/seo优化培训多少钱
  • 建站行业/外包网络推广营销
  • 浙江通管局 网站备案如何好注销/百度推广是什么
  • 单位网站设计建议书/网站营销策划公司
  • 网站建设操作/谷歌全球营销
  • 有没有国外的做美食的视频网站/武汉seo招聘信息
  • 网站建设哪家公司便宜/品牌推广战略
  • ps做网站效果图制作过程/四川seo排名
  • 网站建设 珠海/阿里云域名注册查询
  • 空气净化器用什么网站做外贸/百度竞价推广效果怎么样
  • 网站做好后还需要维护吗/优化网站推广教程整站