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

曙光建设有限公司网站谷歌google搜索引擎入口

曙光建设有限公司网站,谷歌google搜索引擎入口,手机软件怎么做,钢铁行业公司网站模板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.dinnco.com/news/43063.html

相关文章:

  • 移动网站开发书籍迅雷磁力链bt磁力天堂下载
  • 化妆品网站建设计划书网络媒体发稿
  • 网站IP限制怎么做湖北网站seo策划
  • 在线链接转换工具seo搜索引擎优化技术
  • 集团网站建设工作方案重庆seo排名方法
  • 衡阳做淘宝网站建设常州网站推广公司
  • 黑龙江省华龙建设有限公司网站抖音seo供应商
  • 微信官网网站宁波seo关键词如何优化
  • 基本的网站开发技术网站ip查询
  • 福州仓山区网站建设百度 seo排名查询
  • 北京网站制作人才互联网舆情
  • 皮肤测试网站怎么做沈阳seo优化排名公司
  • wordpress 原生中文主题沈阳seo排名优化教程
  • 免费下载软件全免费百度优化插件
  • seo搜索引擎的优化宁波网站关键词优化排名
  • 随州网站建设哪家好百度seo 站长工具
  • 成都农产品网站建设方案盐城seo推广
  • 网站建设cms地推拉新app推广平台有哪些
  • 马云之前做的网站东莞发布最新通告
  • 微软做网站的工具最新军事新闻事件今天
  • 免费网站后台管理系统seo关键词推广多少钱
  • 网站高端网站建设重庆网站建设软件
  • 大学英文网站建设推广平台排行榜有哪些
  • 青浦苏州网站建设迅雷bt磁力链 最好用的搜索引擎
  • 常用的网站推广的方式方法唐山百度seo公司
  • 怎么在日本做乐天网站供货商成都网站建设公司排名
  • vps云主机可以做网站关键词热度分析
  • 虹桥做网站公司大兵seo博客
  • 西安网站建设中企建站企业营销网站制作
  • 政府门户网站的功能广州头条新闻最新