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

物流网站模板免费微信公众号怎么创建内容

物流网站模板免费,微信公众号怎么创建内容,深圳均安网站制作,宁波seo外包联系方式Memcached是一个开源、高性能,将数据分布于内存中并使用key-value存储结构的缓存系统。它通过在内存中缓存数据来减少向数据库的频繁访问连接的次数,可以提高动态、数据库驱动之类网站的运行速度。 Memcached在使用是比较简单的,在操作上基本…

Memcached是一个开源、高性能,将数据分布于内存中并使用key-value存储结构的缓存系统。它通过在内存中缓存数据来减少向数据库的频繁访问连接的次数,可以提高动态、数据库驱动之类网站的运行速度。

Memcached在使用是比较简单的,在操作上基本就类似于操作字典结构的对象一样

1 添加依赖

这里需要添加上web、swagger和spymemcached的依赖,Swagger是为了方便接口测试。

对于spymemcached的支持,其实只要如下这个依赖包就可以了。

<!-- https://mvnrepository.com/artifact/net.spy/spymemcached -->
<dependency><groupId>net.spy</groupId><artifactId>spymemcached</artifactId><version>2.12.3</version>
</dependency>

2 添加相关配置

2.1 添加swagger 配置

添加一个swagger 配置类,在工程下新建 config 包并添加一个 SwaggerConfig 配置类,除了常规配置外,加了一个令牌属性,可以在接口调用的时候传递令牌。

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;@Configuration
@EnableSwagger2
public class SwaggerConfig {@Beanpublic Docket createRestApi(){return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().apis(RequestHandlerSelectors.any()).paths(PathSelectors.any()).build();}private ApiInfo apiInfo(){return new ApiInfoBuilder().title("Swagger API Doc").description("This is a restful api document of Swagger.").version("1.0").build();}}
2.2.在配置文件添加memcache的主机端口信息

application.properties

memcache.ip=127.0.0.1
memcache.port=11211

application.yml

memcache:ip: 127.0.0.1port: 11211
2.3.添加一个MemcacheConfig配置类,读取主机端口并构造一个MemcachedClient。

MemcacheConfig.java

import java.io.IOException;
import java.net.InetSocketAddress;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import net.spy.memcached.MemcachedClient;@Configuration
public class MemcacheConfig {@Value("${memcache.ip}")private String ip;@Value("${memcache.port}")private int port;@Beanpublic MemcachedClient getClient() {MemcachedClient memcachedClient = null;try {memcachedClient  = new MemcachedClient(new InetSocketAddress(ip, port));} catch (IOException e) {e.printStackTrace();}return memcachedClient;}
}
2.4 编写业务接口

编写一个业务控制器,通过MemcachedClient实现对缓存的设置和读取。

MemcacheController.java

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import net.spy.memcached.MemcachedClient;
import net.spy.memcached.internal.OperationFuture;@RestController
public class MemcacheController {private Logger logger = LoggerFactory.getLogger(getClass());@Autowiredprivate MemcachedClient memcachedClient;@GetMapping("/info")public String memcacheGetValue() throws InterruptedException {// 取出缓存Object value = memcachedClient.get("userName");logger.info("取出缓存 "+value);return "取出的值  "+value;}@GetMapping("/save")public String saveValue(@RequestParam String userName) throws InterruptedException {// 放入缓存, 过期时间为5000,单位为毫秒OperationFuture<Boolean> flag = memcachedClient.set("userName", 5000, userName);return "保存成功";}
}

3 编译运行测试

3.1. 右键项目 -> Run as -> Maven install,开始执行Maven构建,第一次会下载Maven依赖,可能需要点时间

在这里插入图片描述

3.2. 右键文件 DemoApplication.java -> Run as -> Java Application,开始启动应用

在这里插入图片描述

3.3. 打开浏览器,访问:http://localhost:8899/swagger-ui.html,进入swagger接口文档界面。

这里的端口根据具体的项目启动来查看,我这里是 8899
在这里插入图片描述

http://www.yayakq.cn/news/702225/

相关文章:

  • 网站网站程序架设wordpress鼠标插件
  • 淄博做网站的公司有哪些wordpress nginx配置文件
  • 网站建设的目的和目标跨境网站入口
  • 做网站要学多久做网站ps分辨率给多少钱
  • 大作设计网站家装设计师工资高吗
  • 中文域名指向同一个网站做一个小说阅读网站怎么做
  • 小型购物网站建设中国国家商标注册网官网
  • 网站的ftp地址是什么开饰品店网站建设预算
  • 网站的seo如何设计沈阳酒店企业网站制作公司
  • delphi10.2 网站开发软件公司主要做哪些
  • 企业建设银行网站登录不了东营会计信息网官网首页
  • 保定seo排名优化优化搜索曝光次数的方法
  • seo网站关键词优化软件网络推广员是干什么的
  • 网域高科学校网站管理系统wordpress建设的是模板网站吗
  • 商品展示的网站源码北京制作网站的公司
  • 学校网站的作用和意义WordPress免插件相册幻灯片
  • 英文网站开发做交互网站
  • 北京海淀建设部大院小区昆明网站优化推广平台
  • 建网站需什么条件购物网站开发 项目描述
  • 英文企业网站源码成都住建官网app
  • 做全网营销型网站建设北京网站开发网站建设价格
  • 用新浪云做网站做婚姻介绍网站赚钱吗
  • 网站开发员一月多少工资东莞网站建设专业品牌
  • 哪个网站找做软件下载淘宝详情页设计
  • 龙岗区网站建设公司高并发系统架构
  • 网站设计规划方案做公众号封面的网站
  • html网站用什么空间正邦设计有限公司
  • 中企建网站免费找订单的平台
  • 上市公司做网站有什么用营销网站有四大要素构成
  • 南京医院手机网站建设怎么自己做游戏