【工具类】cookie工具类封装

springboot封装JsonUtil,CookieUtil工具类代码实例 主要介绍了springboot封装JsonUtil,CookieUtil工具类过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 立即下载
/* 设置cookie */
function setCookie (cName, value, options) {
    options = options||{};
    let expire = null;
    if(options.hour){
      let today = new Date();
      expire = new Date();
      expire.setTime(today.getTime() + options.hour * 3600000);
    }
    window.document.cookie =
      cName + '=' + value
      + (options.path ? '; path=' + options.path : '')
      + (options.hour ? '; expires=' + expire.toGMTString() : '')
      + (options.domain ? '; domain=' + options.domain : '');
    return this;
}
  
/* 获取cookie */
function getCookie (cName) {
    if (document.cookie.length > 0) {
      let cStart = document.cookie.indexOf(cName + '=')
      if (cStart !== -1) {
        cStart = cStart + cName.length + 1
        let cEnd = document.cookie.indexOf(';', cStart)
        if (cEnd === -1) cEnd = document.cookie.length
        return unescape(document.cookie.substring(cStart, cEnd))
      }
    }
    return ''
}
  
/* 删除cookie */
function delCookie (cName) {
  setCookie(cName, '', -1)
}


export default {
  setCookie,
  getCookie,
  delCookie
}

 使用:

//这里使用的方式是将cookie工具类挂载到vue上
import cookie from './utils/cookie';
Vue.prototype.$cookie = cookie;



//示例cookie存储
this.$cookie.setCookie('tk', res.data.token, {hour: 24 * 14 });
this.$cookie.setCookie('username', this.form.username, {hour: 24 * 14 });

 

自己的js工具 Cookie 封装 这个时候我们最好是将cookie操作封装起来,便于重用啊 ===================== 代码如下: /** 类 Cookie 将此类放入用到的js文件中即可使用 1.add(name,value,100); 添加一个cookie 2.get(name); 3.remove(name); 用例: Cookie.add(“sk”,”ss”,3); alert(cookie.get(“sk”)); Cookie.remove(“sk”); */ var Cookie=new function(){ //添加cookie this.add=function(name,value,hou 立即下载

相关推荐

别再只看pLDDT了!AlphaFold预测结果解读保姆级指南:pLDDT、PAE、pTM、ipTM到底怎么看?

本文详细解析了AlphaFold预测结果中的关键指标pLDDT、PAE、pTM和ipTM,帮助用户从单一依赖pLDDT进阶到全面理解蛋白质结构预测。通过实际案例和技巧,指导如何正确解读这些指标,避免常见错误,并提供了从预测到发表的实用建议。

weixin_29100399的博客 357

Vue2 和 Vue3 封装 axios和cookies,完成请求效验

本文归纳整理vue2和vue3 对axios的封装代码,以及如何在web端操作使用cookies中存储的token来做效验之类的操作。vue2 使用的是 axios+vue-cookies组件实现vue3 使用的是 axios+js-cookies组件实现。

isLTH的博客 3211

UE5游戏逆向实战:用FModel提取.pak文件中的3D模型(附Dumper-7避坑指南)

本文详细介绍了如何使用FModel工具从UE5游戏的.pak文件中提取3D模型,并提供了Dumper-7的避坑指南。内容涵盖FModel工具链配置、UE5特有的unversioned properties问题解决方案、Dumper-7实战流程以及模型后处理技巧,帮助开发者高效获取游戏资产。

weixin_30872499的博客 424

推荐Vue-Cookie:强大的Vue.js Cookie管理库

是一个轻量级但功能丰富的Vue.js插件,它使得在Vue应用中处理Cookie变得简单易行。通过这个库,开发者可以轻松地读取、设置和删除Cookie,从而更好地实现用户状态管理和个性化体验。 ## 技术分析 Vue-Cookie的核心是其直观且易于理解的API设计。以下是其主要特性: 1. **全局`this.$cookie`方法** - Vue-Cookie将自身注入到每个Vue实例中,因

gitblog_00049的博客 675

开源TMS系统cortex-tms私有化部署与二次开发实战指南

运输管理系统(TMS)是现代物流数字化的核心组件,它通过将线下零散的物流操作转化为线上标准化、可追溯的数据流,实现订单、调度、跟踪与结算的全流程管理。其技术原理通常基于微服务架构,采用Spring Boot、Vue.js等成熟技术栈构建,确保系统的稳定性和可扩展性。TMS的技术价值在于显著提升物流企业的运营效率、降低成本并增强过程可控性,尤其适用于中小型物流企业实现从手工管理到系统化管理的跨越。在应用场景上,TMS广泛应用于车队管理、订单跟踪和财务结算等环节。本文聚焦于开源TMS项目cortex-tms,深

weixin_42523907的博客 747

cst-python联合仿真的问题解决

cst与python联合仿真出现无法调用CST的问题解决

ayihu_的博客 2374

Vue第 35 篇,js-cookie和vue-cookies(Cookie使用教程)

⭐Cookies是网站发送至用户浏览器的小型文本文件,存储于用户设备上,用于追踪用户活动、保存偏好设置及维护登录状态。当用户重访网站时,浏览器会回传Cookies信息,使网站能识别用户,提供个性化服务。简而言之,Cookies帮助网站记住用户,实现定制化体验。 而js-cookie和vue-cookies都是vue项目中的插件。下载相关依赖后,可以在项目中用来存储、获取、删除Cookie等操作,思路相同,但操作时稍有不同,当然也可以用原生js来获取Cookie。这里来简单记录一下

AI Agent 全栈架构师(AI + GIS + Backend)& 数字芯片系统架构师(FPGA),NorthCity Smile的博客(NcSmile,博主域名:https://ncmile.blog.youkuaiyun.com) 5506

RH850系列芯片深度剖析 1.5-链接(ld)文件解析

基础编译过程分为四个阶段:预处理(Preprocessing)、编译(Compilation)、汇编(Assembly)、链接(Linking)。执行这四个阶段的程序(预处理器、编译器、汇编器、和链接器)一起构成了编译系统。CONSTANTS接下来的内存空间定义部分会使用这些常量来定义内存空间的范围,理论上来说不定义常量也没有影响,直接用魔鬼数字代替,定义常量的主要目的就是方便理解以及方便修改;从示例中可以看出,常量的值可以为16进制或者10十进制,而且10进制支持数量级单位(k级,M级);

本博客专注于嵌入式软件领域技术分享。 1430

js 原生cookie封装

文章目录原生cookie的使用cookie存储cookie获取cookie修改cookie删除cookie封装cookie简单使用cookie封装工具类 原生cookie的使用 cookie存储 document.cookie = "name=111"; cookie获取 //存储cookies document.cookie = "name=111"; //获取cookies var cookies = document.cookie; console.log(cookies); cookie修改 /

weixin_47790139的博客 767

扰动观察法MPPT控制器simulink仿真

最大功率点跟踪(MPPT)控制器对于光伏(PV)系统至关重要,因为它可以确保系统在所有操作条件下都能从光伏阵列中提取最大功率。扰动观察法(P&O)是一种广泛使用的MPPT算法,因为它简单且易于实现。本文介绍了P&O MPPT控制器的Simulink仿真,并分析了其性能。

qq_59747472的博客 318

国科大学习资料--遥感原理集图像处理(尤红建)--2019年期末考试

国科大学习资料–遥感原理集图像处理(尤红建)–2019年期末考试 国科大学习资料–遥感原理集图像处理(尤红建)–2019年期末考试 国科大学习资料–遥感原理集图像处理(尤红建)–2019年期末考试 ================================================================== ================================================================== ==============

无名何许人的博客 1470

vue封装cookie及使用

1、在utils文件夹中新建cookies.js文件用来存放公共的方法。 / /** @author xxxx @description 保存cookie @param {String} name 需要存储cookie的key @param {String} value 需要存储cookie的value @param {Number} timer 默认存储多少天 / function setCo...

weixin_44974357的博客 625

set_input_delay/set_output_delay介绍

针对这一类的情况,在做block时,cts之后,便需要将update_io_latency给关闭。那么,计算的timing就是错误的了。对于hier flow来讲,切分block,进行timing budget的时候,clock tree还未长。计算block端口上的timing,通常需要用到set_input_delay和set_output_delay告知工具外部电路的延迟信息,以方便工具计算端口上的timing。此时,工具在计算in2reg的timing时,便会将2.67ns的delay带进来。

芯冰乐 320

简单封装浏览器 cookie 工具类

简单封装浏览器 cookie 工具类 目前主流浏览器一般都支持 cookie ,以下对 cookie 的操作进行简单封装,以方便使用 更多精彩 更多技术博客,请移步 asing1elife’s blog 主体封装类 import { storagePrefix } from 'assets/scripts/config/config' import { verify,...

asing1elife's blog 623

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

cookie工具类 java_springboot封装JsonUtil,CookieUtil工具类代码实例

这篇文章主要介绍了springboot封装JsonUtil,CookieUtil工具类过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下JsonUtilpublic class JsonUtil {private static ObjectMapper objectMapper = new ObjectMapper();public stat...

weixin_34254464的博客 311

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

es封装cookie工具类

CookieUtil.js const CookieUtil={ get(name){ let cookieName=encodeURIComponent(name)+"=", cookieStart=document.cookie.indexOf(cookieName), cookieValue=null;

wp12345666666的博客 669

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

es6封装的子cookie工具类

SubCookieUtil.js let SubCookieUtil = { get(name, subName){ let subCookies = this.getAll(name); if (subCookies) { return subCookies[subName]; } else {

wp12345666666的博客 1327

原生JavaScript封装cookie工具类

export default{ /* 设置cookie key:String 键名 val:String 值 expires:string 到期时间 单位秒 */ setCookie(key,val,expires){ let nowTime = new Date().getTime(); let endTime = new Date(nowTime + expires*1000);

qq_41591368的博客 218

使用JAVA类对Cookie的简单操作进行封装

使用JAVA类对Cookie的简单操作进行封装简介相关知识方法表参数表 简介 在使用JSP写web项目时,总是会和Cookie打交道,所以就封装了一个Cookie的工具类,方便每次使用,只封装了最基础的几个操作,如果有错误还请大家帮忙指正。 相关知识 Cookie详解这个写的不错 方法表 方法名 作用 addCookie(HttpServletResponse response, String key, String value, int age) 添加Cookie addCookie(

买烤麸烤饼儿的博客 370

Java Cookie工具类代码

Java Cookie工具类代码 添加cookie(设置有效时间) 检索所有cookie 封装到map集合 以其cookie name作为key cookie value作为value 通过cookie name 获取 cookie value import java.util.HashMap; import java.util.Map;import javax.servlet.http.Cooki

X-rapido的专栏 1976

JAVA——保持cookie登录状态的HttpClient封装工具类

在日常开发中,我们经常需要通过http协议去调用网络内容,虽然java自身提供了net相关工具包,但是其灵活性和功能总是不如人意,于是有人专门搞出一个httpclient类库,来方便进行Http操作。简单的对httpcient的简单操作封装成一个工具类,统一放在项目的工具包中,在使用的时候直接从工具包中调用,不需要写冗余代码。 Maven <dependency> <groupId>org.apache.httpcomponents<

无限迭代中...... 1188

轻松把玩HttpClient之封装HttpClient工具类(五),携带Cookie的请求

最近更新了一下HttpClientUtil工具类代码,主要是添加了一个参数HttpContext,这个是用来干嘛的呢?其实是用来保存和传递Cookie所需要的。因为我们有很多时候都需要登录,然后才能请求一些想要的数据。而在这以前使用HttpClientUtil工具类,还不能办到。现在更新了以后,终于可以了。       先说一下思路:本次的demo,就是获取csdn中的c币,要想获取c币,必须先登

崔成龙 . 勇往直前 1万+

java cookie操作_java Cookie操作工具类

package com.xxxx.common.util;import javax.servlet.http.Cookie;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;/*** @Package: com.xxxxx.common.util* @Title: C...

weixin_32484897的博客 116

Cookie 操作工具类

import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * @Package: com.xxxxx.common.util * @Title: Cookie.java Crea...

weixin_34144848的博客 95
上一篇: 将已有项目导入svn
下一篇: 【vuex学习】vuex基本使用及模块拆分
谭CV
博客等级 码龄9年 73粉丝 85原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值