springboot使用elasticsearch的客户端操作eslaticsearch
一 ES客户端
ES提供多种不同的客户端:
1、TransportClient
ES提供的传统客户端,官方计划8.0版本删除此客户端。
2、RestClient
RestClient是官方推荐使用的,它包括两种:Java Low Level REST Client和 Java High Level REST Client。
ES在6.0之后提供 Java High Level REST Client, 两种客户端官方更推荐使用 Java High Level REST Client,不过当前它还处于完善中,有些功能还没有。
3 spring-data-elasticsearch
这个是基于TransportClient开发的,虽然在有些版本还是可以用,但是更新对应版本太慢了
采用 Java High Level REST Client,如果它有不支持的功能,则使用Java Low Level REST Client。
二 整合
首先是pom.xml
注意我这个地方引入的是springbooot2.0.1 版本,首先这么做下去,再升级
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0..RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.cxy</groupId>
<artifactId>elasticsearch</artifactId>
<version>0.0.-SNAPSHOT</version>
<name>elasticsearch</name>
<description>Demo project for Spring Boot</description> <properties>
<java.version>1.8</java.version>
</properties> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>6.2.</version>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>6.2.</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> </project>
yml文件:
server:
port: ${port:}
spring:
application:
name:search-service
elasticsearch:
hostlist: ${eshostlist:127.0.0.1:}
es的配置类:
package com.cxy.elasticsearch.config; import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; @Configuration
public class ElasticsearchConfig { @Value("${spring.elasticsearch.hostlist}")
private String hostlist; @Bean
public RestHighLevelClient restHighLevelClient(){
//解析hostlist配置信息
String[] split = hostlist.split(",");
//创建HttpHost数组,其中存放es主机和端口的配置信息
HttpHost[] httpHostArray = new HttpHost[split.length];
for(int i=;i<split.length;i++){
String item = split[i];
httpHostArray[i] = new HttpHost(item.split(":")[], Integer.parseInt(item.split(":")[]), "http");
}
//创建RestHighLevelClient客户端
return new RestHighLevelClient(RestClient.builder(httpHostArray));
} //项目主要使用RestHighLevelClient,对于低级的客户端暂时不用
@Bean
public RestClient restClient(){
//解析hostlist配置信息
String[] split = hostlist.split(",");
//创建HttpHost数组,其中存放es主机和端口的配置信息
HttpHost[] httpHostArray = new HttpHost[split.length];
for(int i=;i<split.length;i++){
String item = split[i];
httpHostArray[i] = new HttpHost(item.split(":")[], Integer.parseInt(item.split(":")[]), "http");
}
return RestClient.builder(httpHostArray).build();
} }
然后再看我的controller
package com.cxy.elasticsearch.controller; import org.elasticsearch.action.DocWriteResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.client.IndicesClient;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map; @RestController
public class EsController {
@Autowired
RestHighLevelClient client; @Autowired
RestClient restClient;
@RequestMapping(value = "/createIndex" ,method = RequestMethod.POST)
public String createIndex(){
//创建索引请求对象
CreateIndexRequest createIndexRequest = new CreateIndexRequest("chenxuyou3");
// 设置参数
createIndexRequest.settings(Settings.builder().put("number_of_shards","").put("number_of_replicas",""));
//指定映射
createIndexRequest.mapping("doc"," {\n" +
" \t\"properties\": {\n" +
" \"studymodel\":{\n" +
" \"type\":\"keyword\"\n" +
" },\n" +
" \"name\":{\n" +
" \"type\":\"keyword\"\n" +
" },\n" +
" \"description\": {\n" +
" \"type\": \"text\",\n" +
" \"analyzer\":\"ik_max_word\",\n" +
" \"search_analyzer\":\"ik_smart\"\n" +
" },\n" +
" \"pic\":{\n" +
" \"type\":\"text\",\n" +
" \"index\":false\n" +
" }\n" +
" \t}\n" +
"}", XContentType.JSON);
//指定索引操作的客户端
IndicesClient indices = client.indices();
//执行创建索引库
CreateIndexResponse createIndexResponse = null;
try {
createIndexResponse = indices.create(createIndexRequest);
} catch (IOException e) {
e.printStackTrace();
}
boolean acknowledged = createIndexResponse.isAcknowledged();
//获取返回结果
System.err.println(acknowledged);
return "ok";
}
@RequestMapping(value = "/deleteIndex",method = RequestMethod.POST)
public String deleteIndex(){
DeleteIndexRequest chenxuyou3 = new DeleteIndexRequest("chenxuyou2");
IndicesClient indices = client.indices();
AcknowledgedResponse delete =null;
try {
delete = indices.delete(chenxuyou3);
} catch (IOException e) {
e.printStackTrace();
}
boolean acknowledged = delete.isAcknowledged();
System.err.println(acknowledged);
return "";
}
@RequestMapping(value = "/addDoc",method = RequestMethod.POST)
public String addDoc(){
//文档内容
//准备json数据
Map<String, Object> jsonMap = new HashMap<>();
jsonMap.put("name", "spring cloud实战");
jsonMap.put("description", "本课程主要从四个章节进行讲解: 1.微服务架构入门 2.spring cloud 基础入门 3.实战Spring Boot 4.注册中心eureka。");
jsonMap.put("studymodel", "");
SimpleDateFormat dateFormat =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
jsonMap.put("timestamp", dateFormat.format(new Date()));
jsonMap.put("price", 5.6f); //创建索引创建对象
//带有type的方法已经废弃
// IndexRequest indexRequest = new IndexRequest("chenxuyou3","doc");
IndexRequest indexRequest = new IndexRequest("chenxuyou3");
//文档内容
indexRequest.source(jsonMap);
//通过client进行http的请求
IndexResponse indexResponse = null;
try {
indexResponse = client.index(indexRequest);
} catch (IOException e) {
e.printStackTrace();
}
DocWriteResponse.Result result = indexResponse.getResult();
System.err.println(result);
return "ok";
}
@RequestMapping(value = "/selectDoc",method = RequestMethod.GET)
public String selectDoc(){
//查询请求对象
// GetRequest getRequest = new GetRequest("chenxuyou2","doc","8tyV-m4B7rvW_ZY4LvVU");
GetRequest getRequest = new GetRequest("chenxuyou3","doc","8tyV-m4B7rvW_ZY4LvVU");
GetResponse getResponse = null;
try {
getResponse = client.get(getRequest);
} catch (IOException e) {
e.printStackTrace();
}
//得到文档的内容
Map<String, Object> sourceAsMap = getResponse.getSourceAsMap();
System.out.println(sourceAsMap);
return "ok" ;
} }
然后启动项目可以看到很清晰的运行
调用 localhost:8085/createIndex
可以看到成功了,后面的也就自然可以操作了。
三 问题一:
修改springboot的版本为2.1.8,环境:我使用的es版本是6.2.1 版本:
出现问题:
{
"timestamp": "2019-12-15T04:46:53.518+0000",
"status": ,
"error": "Internal Server Error",
"message": "org.elasticsearch.client.Request.<init>(Ljava/lang/String;Ljava/lang/String;)V",
"path": "/createIndex"
}
控制台:
java.lang.NoSuchMethodError: org.elasticsearch.client.Request.<init>(Ljava/lang/String;Ljava/lang/String;)V
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:) ~[elasticsearch-rest-client-6.4..jar:6.2.]
at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:) ~[elasticsearch-rest-high-level-client-6.2..jar:6.2.]
at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:) ~[elasticsearch-rest-high-level-client-6.2..jar:6.2.]
at org.elasticsearch.client.IndicesClient.create(IndicesClient.java:) ~[elasticsearch-rest-high-level-client-6.2..jar:6.2.]
at com.cxy.elasticsearch.controller.EsController.createIndex(EsController.java:) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_191]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:) ~[na:1.8.0_191]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:) ~[na:1.8.0_191]
at java.lang.reflect.Method.invoke(Method.java:) ~[na:1.8.0_191]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:) ~[spring-web-5.1..RELEASE.jar:5.1..RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:) ~[spring-web-5.1..RELEASE.jar:5.1..RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:) ~[spring-webmvc-5.1..RELEASE.jar:5.1..RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:) ~[spring-webmvc-5.1..RELEASE.jar:5.1..RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:) ~[spring-webmvc-5.1..RELEASE.jar:5.1..RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:) ~[spring-webmvc-5.1..RELEASE.jar:5.1..RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:) ~[spring-webmvc-5.1..RELEASE.jar:5.1..RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:) ~[spring-webmvc-5.1..RELEASE.jar:5.1..RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:) ~[spring-webmvc-5.1..RELEASE.jar:5.1..RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:) ~[spring-webmvc-5.1..RELEASE.jar:5.1..RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:) ~[tomcat-embed-core-9.0..jar:9.0.]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:) ~[spring-webmvc-5.1..RELEASE.jar:5.1..RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:) ~[tomcat-embed-core-9.0..jar:9.0.]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:) ~[tomcat-embed-core-9.0..jar:9.0.]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:) ~[tomcat-embed-core-9.0..jar:9.0.]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:) ~[tomcat-embed-websocket-9.0..jar:9.0.]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:) ~[tomcat-embed-core-9.0..jar:9.0.]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:) ~[tomcat-embed-core-9.0..jar:9.0.]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:) ~[spring-web-5.1..RELEASE.jar:5.1..RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:) ~[spring-web-5.1..RELEASE.jar:5.1..RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:) ~[tomcat-embed-core-9.0..jar:9.0.]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:) ~[tomcat-embed-core-9.0..jar:9.0.]
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:) ~[spring-web-5.1..RELEASE.jar:5.1..RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:) ~[spring-web-5.1..RELEASE.jar:5.1..RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:) ~[tomcat-embed-core-9.0..jar:9.0.]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:) ~[tomcat-embed-core-9.0..jar:9.0.]
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:) ~[spring-web-5.1..RELEASE.jar:5.1..RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:) ~[spring-web-5.1..RELEASE.jar:5.1..RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:) ~[tomcat-embed-core-9.0..jar:9.0.]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:) ~[tomcat-embed-core-9.0..jar:9.0.]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:) ~[spring-web-5.1..RELEASE.jar:5.1..RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:) ~[spring-web-5.1..RELEASE.jar:5.1..RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:) ~[tomcat-embed-core-9.0..jar:9.0.]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:) ~[tomcat-embed-core-9.0..jar:9.0.]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:) ~[tomcat-embed-core-9.0..jar:9.0.]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:) [tomcat-embed-core-9.0..jar:9.0.]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:) [tomcat-embed-core-9.0..jar:9.0.]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:) [tomcat-embed-core-9.0..jar:9.0.]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:) [tomcat-embed-core-9.0..jar:9.0.]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:) [tomcat-embed-core-9.0..jar:9.0.]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:) [tomcat-embed-core-9.0..jar:9.0.]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:) [tomcat-embed-core-9.0..jar:9.0.]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:) [tomcat-embed-core-9.0..jar:9.0.]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:) [tomcat-embed-core-9.0..jar:9.0.]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:) [tomcat-embed-core-9.0..jar:9.0.]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:) [tomcat-embed-core-9.0..jar:9.0.]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:) [na:1.8.0_191]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:) [na:1.8.0_191]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:) [tomcat-embed-core-9.0..jar:9.0.]
at java.lang.Thread.run(Thread.java:) [na:1.8.0_191]
java.lang.NoSuchMethodError: org.elasticsearch.client.Request.<init>(Ljava/lang/String;Ljava/lang/String;)V
这句话的具体意思是这样的,就是没有这个方法,Request对象init的时候创建使用(String,String)后面v是值得意思
可以很清楚,就是升级时候,这个方法没了
/** @deprecated */
@Deprecated
public Response performRequest(String method, String endpoint, Map<String, String> params, Header... headers) throws IOException {
Request request = new Request(method, endpoint);
addParameters(request, params);
addHeaders(request, headers);
return this.performRequest(request);
}
由于这个方法已经废弃了,所以在重新去找的时候,版本升级,springboot就没有去找这个类,
所以就报错了
四 问题二
出现了上叙问题之后,我想到了解决方法,就是将client得版本升级为最新得,7.23
然后还有就是他那个type得移除,构造方法里面不能有type
最终由于跟我es版本不一致,
Search problem, contains unrecognized parameter: [typed_keys]
报包含错误得字段,我在删除得时候明没什么都没有
然后将版本进行升级:升级到6.6.1就成功了
springboot使用elasticsearch的客户端操作eslaticsearch的更多相关文章
- ElasticSearch相关概念与客户端操作
一.Elasticsearch概述 Elasticsearch是面向文档(document oriented)的,这意味着它可以存储整个对象或文档(document).然而它不仅仅是存储,还会索引(i ...
- springboot整合es客户端操作elasticsearch(五)
springboot整合es客户端操作elasticsearch的总结: 客户端可以进行可以对所有文档进行查询,就是不加任何条件: SearchRequest searchRequest = new ...
- springboot整合es客户端操作elasticsearch(二)
在上章节中整合elasticsearch客户端出现版本问题进行了处理,这章来进行springboot整合得操作 环境:elaticsearch6.2.1,springboot 2.1.8 客户端版本采 ...
- 使用Java客户端操作elasticsearch(二)
承接上文,使用Java客户端操作elasticsearch,本文主要介绍 常见的配置 和Sniffer(集群探测) 的使用. 常见的配置 前面已介绍过,RestClientBuilder支持同时提供一 ...
- SpringBoot整合ElasticSearch实现多版本的兼容
前言 在上一篇学习SpringBoot中,整合了Mybatis.Druid和PageHelper并实现了多数据源的操作.本篇主要是介绍和使用目前最火的搜索引擎ElastiSearch,并和Spring ...
- ElasticSearch+Kibana 索引操作( 附源码)
一 前言 ElasticiSearch 简介 ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口.Elastics ...
- ElasticSearch+Kibana 索引操作
ElasticSearch+Kibana 索引操作 一 前言 ElasticiSearch 简介 ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引 ...
- 全文检索-Elasticsearch (四) elasticsearch.net 客户端
本篇摘自elasticsearch.net search入门使用指南中文版(翻译) 原文:http://edu.dmeiyang.com/book/nestusing.html elasticsear ...
- springboot集成elasticsearch
在基础阶段学习ES一般是首先是 安装ES后借助 Kibana 来进行CURD 了解ES的使用: 在进阶阶段可以需要学习ES的底层原理,如何通过Version来实现乐观锁保证ES不出问题等核心原理: 第 ...
随机推荐
- 计数dp做题笔记
YCJS 3924 饼干 Description 给定一个长度为\(n\)的序列,序列每个元素的取值为\([1,x]\),现在给定\(q\)个区间,求在所有取值方案中,区间最小值的最大值的期望是多少? ...
- http method
get: 获取资源get方法用来请求访问已被URL识别的资源 post: 传输实体主体POST方法用来传输实体的主体 put: 传输文件PUT方法用来传输文件. head: 获取报文首部head方法与 ...
- Java进阶知识15 Spring的基础配置详解
1.SSH各个的职责 Struts2:是web框架(管理jsp.action.actionform等).Hibernate:是ORM框架,处于持久层.Spring:是一个容器框架,用于配置bean,并 ...
- Centos 7 搭建蓝鲸V4.1.16稳定社区版
在本地用VMware模拟了三台主机 准备至少3台 CentOS 7 以上操作系统的机器,保证三台虚拟机都可以上网 最低配置:2核4G(我用的是这个) 建议配置: 4核12G 以上 192.168.16 ...
- neo4j︱与python结合的py2neo使用教程
—- 目前的几篇相关:—– neo4j︱图数据库基本概念.操作罗列与整理(一) neo4j︱Cypher 查询语言简单案例(二) neo4j︱Cypher完整案例csv导入.关系联通.高级查询(三) ...
- 爬虫之requests库的使用
get基本请求 响应对象的属性: # 获取响应对象中的内容是str格式 text # 获取响应对象中的内容是二进制格式的 content # 获取响应状态码 status_code # 获取响应头信息 ...
- Python datetime库计算两个时间点之间的分钟(秒、天)数
计算两个时间点之间的分钟数 import datetime def minNums(startTime, endTime): '''计算两个时间点之间的分钟数''' # 处理格式,加上秒位 start ...
- phpstorm配置了git后Terminal 不能使用显示:git' 不是内部或外部命令,也不是可运行的程序
问题:在phpstorm上配置好git后,将代码拉了下来 ,但是命令行无法使用显示如图 解决方法:①找到安装git的位置,然后在该目录的子目录下分别找到git-core.bin 两个目录,我的安装在了 ...
- 中间件 | Nginx实现动静分离
Nginx动静分离基本概述 动静分离,通过中间件将动静分离和静态请求进行分离: 通过中间件将动态请求和静态请求分离,可以建上不必要的请求消耗,同事能减少请求的延时. 通过中间件将动态请求和静态请求分离 ...
- C realloc
https://baike.baidu.com/item/realloc/659993?fr=aladdin 也就是说:原地址后面有连续可以空间可以满足需要,则追加在后面,否则开辟新空间,并拷贝数据