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

莆田山亭乡建设局网站5ucms怎样做网站自适应

莆田山亭乡建设局网站,5ucms怎样做网站自适应,成都网站关键字优化,定制衣服的软件app文章目录 第一步#xff0c;导入jar包#xff0c;注意这里的jar包版本可能和你导入的不一致#xff0c;所以需要修改第二步#xff0c;编写配置类第三步#xff0c;填写yml第四步#xff0c;编写util类第五步#xff0c;编写controller类第六步#xff0c;测试即可 第一… 文章目录 第一步导入jar包注意这里的jar包版本可能和你导入的不一致所以需要修改第二步编写配置类第三步填写yml第四步编写util类第五步编写controller类第六步测试即可 第一步导入jar包注意这里的jar包版本可能和你导入的不一致所以需要修改 properties propertiesjava.version1.8/java.versionelasticsearch.version7.6.2/elasticsearch.version /properties!-- elasticsearch -- !--es客户端-- dependencygroupIdorg.elasticsearch.client/groupIdartifactIdelasticsearch-rest-high-level-client/artifactIdversion7.6.2/version /dependency!--springboot的elasticsearch服务-- dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-data-elasticsearch/artifactId /dependency第二步编写配置类 这段代码是一个基本的 Elasticsearch Java 客户端的配置类用于创建一个 RestHighLevelClient 实例。 其中 RestHighLevelClient 是 Elasticsearch Java 客户端的高级别别名是基于 LowLevelClient 之上的封装提供了一些更加方便的方法和功能。 在这段代码中使用了 Value 注解来注入三个配置项包括 hostnameport 和 scheme。这三个配置项分别表示 Elasticsearch 服务器的主机名或 IP 地址端口号和通信协议。然后使用RestClient.builder() 方法来创建一个 RestClient 实例传入 Elasticsearch 服务器的地址和端口号最后将 RestClient 实例传入 RestHighLevelClient 的构造函数中即可创建一个 RestHighLevelClient 实例。 需要注意的是这段代码中的 RestHighLevelClient 实例是一个单例对象只需要在应用程序启动时创建一次即可因此这个类应该被配置为一个 Spring Bean以便在需要时注入到其他类中使用。 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 ElasticSearchClientConfig {Value(${elasticSearch.hostname})private String hostname;Value(${elasticSearch.port})private Integer port;Value(${elasticSearch.scheme})private String scheme;Beanpublic RestHighLevelClient restHighLevelClient(){return new RestHighLevelClient(RestClient.builder(new HttpHost(hostname,port,scheme)));} }第三步填写yml elasticSearch:hostname: 127.0.0.1port: 9200scheme: http第四步编写util类 这是一个Java类实现了Elasticsearch API的一些基本功能。它定义了创建、检查是否存在、删除索引、添加、修改和删除文档以及搜索文档的方法。该类使用Elasticsearch API的RESTful客户端来执行这些操作。 以下是每种方法的概述 createIndex字符串索引使用给定的名称创建一个索引。existIndex字符串索引检查是否存在具有给定名称的索引。deleteIndex字符串索引删除具有给定名称的索引。addDocument动态动态字符串索引使用给定的名称将文档添加到索引中。existDocument字符串索引字符串文档检查具有给定ID的文档是否存在于具有给定名称的索引中。getDocument字符串索引字符串文档从具有给定名称的索引中检索具有给定ID的文档。updateDocument动态动态、字符串索引、字符串文档在具有给定名称的索引中更新具有给定ID的文档。deleteDocument字符串索引字符串文档从具有给定名称的索引中删除具有给定ID的文档。bulkAddDocumentListDynamicdynamics在一个批次中将多个具有给定名称的文档添加到索引中。searchDocument字符串索引根据搜索查询在索引中搜索具有给定名称的文档。 import com.alibaba.fastjson.JSON; import com.wangfugui.apprentice.dao.domain.Dynamic; import lombok.extern.slf4j.Slf4j; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; import org.elasticsearch.action.bulk.BulkRequest; import org.elasticsearch.action.bulk.BulkResponse; import org.elasticsearch.action.delete.DeleteRequest; import org.elasticsearch.action.delete.DeleteResponse; 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.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.support.master.AcknowledgedResponse; import org.elasticsearch.action.update.UpdateRequest; import org.elasticsearch.action.update.UpdateResponse; import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.client.indices.CreateIndexRequest; import org.elasticsearch.client.indices.CreateIndexResponse; import org.elasticsearch.client.indices.GetIndexRequest; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.TermQueryBuilder; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.builder.SearchSourceBuilder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Component;import java.io.IOException; import java.util.List; import java.util.concurrent.TimeUnit;/*** since JDK 1.8.0*/ Component Slf4j public class ElasticSearchUtil {AutowiredQualifier(restHighLevelClient)private RestHighLevelClient client;//索引的创建public CreateIndexResponse createIndex(String index) throws IOException {//1.创建索引的请求CreateIndexRequest request new CreateIndexRequest(index);//2客户端执行请求请求后获得响应CreateIndexResponse response client.indices().create(request, RequestOptions.DEFAULT);log.info(索引的创建{}, response);return response;}//索引是否存在public Boolean existIndex(String index) throws IOException {//1.创建索引的请求GetIndexRequest request new GetIndexRequest(index);//2客户端执行请求请求后获得响应boolean exist client.indices().exists(request, RequestOptions.DEFAULT);log.info(索引是否存在----- exist);return exist;}//删除索引public Boolean deleteIndex(String index) throws IOException {DeleteIndexRequest request new DeleteIndexRequest(index);AcknowledgedResponse delete client.indices().delete(request, RequestOptions.DEFAULT);log.info(删除索引-------- delete.isAcknowledged());return delete.isAcknowledged();}//添加文档public IndexResponse addDocument(Dynamic dynamic, String index) throws IOException {IndexRequest request new IndexRequest(index);//设置超时时间request.timeout(1s);//将数据放到json字符串request.source(JSON.toJSONString(dynamic), XContentType.JSON);//发送请求IndexResponse response client.index(request, RequestOptions.DEFAULT);log.info(添加文档------- response.toString());log.info(添加文档------- response.status());return response;}//文档是否存在public Boolean existDocument(String index, String documents) throws IOException {//文档的 没有indexGetRequest request new GetRequest(index, documents);//没有indices()了boolean exist client.exists(request, RequestOptions.DEFAULT);log.info(文档是否存在----- exist);return exist;}//获取文档public GetResponse getDocument(String index, String documents) throws IOException {GetRequest request new GetRequest(index, documents);GetResponse response client.get(request, RequestOptions.DEFAULT);log.info(获取文档----- response.getSourceAsString());log.info(获取文档----- response);return response;}//修改文档public UpdateResponse updateDocument(Dynamic dynamic, String index, String documents) throws IOException {//修改是id为1的UpdateRequest request new UpdateRequest(index, documents);request.timeout(1s);request.doc(JSON.toJSONString(dynamic), XContentType.JSON);UpdateResponse response client.update(request, RequestOptions.DEFAULT);log.info(修改文档----- response);log.info(修改文档----- response.status());return response;}//删除文档public RestStatus deleteDocument(String index, String documents) throws IOException {DeleteRequest request new DeleteRequest(index, documents);request.timeout(1s);DeleteResponse response client.delete(request, RequestOptions.DEFAULT);log.info(删除文档------ response.status());return response.status();}//批量添加文档public BulkResponse bulkAddDocument(ListDynamic dynamics) throws IOException {//批量操作的RequestBulkRequest request new BulkRequest();request.timeout(1s);//批量处理请求for (int i 0; i dynamics.size(); i) {request.add(new IndexRequest(lisen_index).id( (i 1)).source(JSON.toJSONString(dynamics.get(i)), XContentType.JSON));}BulkResponse response client.bulk(request, RequestOptions.DEFAULT);//response.hasFailures()是否是失败的log.info(批量添加文档----- response.hasFailures());// 结果:false为成功 true为失败return response;}//查询文档public SearchResponse searchDocument(String index) throws IOException {SearchRequest request new SearchRequest(index);//构建搜索条件SearchSourceBuilder sourceBuilder new SearchSourceBuilder();//设置了高亮sourceBuilder.highlighter();//term name为cyx1的TermQueryBuilder termQueryBuilder QueryBuilders.termQuery(name, cyx1);sourceBuilder.query(termQueryBuilder);sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));request.source(sourceBuilder);SearchResponse response client.search(request, RequestOptions.DEFAULT);log.info(查询文档----- JSON.toJSONString(response.getHits()));log.info();for (SearchHit documentFields : response.getHits().getHits()) {log.info(查询文档--遍历参数-- documentFields.getSourceAsMap());}return response;}public IndexResponse addDocumentId(Dynamic dynamic, String index, String id) throws IOException {IndexRequest request new IndexRequest(index);//设置超时时间request.id(id);//将数据放到json字符串request.source(JSON.toJSONString(dynamic), XContentType.JSON);//发送请求IndexResponse response client.index(request, RequestOptions.DEFAULT);log.info(添加文档------- response.toString());log.info(添加文档------- response.status());return response;} }第五步编写controller类 这是一个Java类实现了Elasticsearch API的一些基本功能。它定义了用于创建、检查存在性、删除索引、添加、修改和删除文档以及搜索文档的方法。该类使用Elasticsearch API的RESTful客户端执行这些操作。 以下是每个方法的概述 createIndex(String index) 创建索引的方法。existIndex(String index) 检查给定名称的索引是否存在的方法。deleteIndex(String index) 删除给定名称的索引的方法。addDocument(Dynamic dynamic, String index) 将文档添加到给定名称的索引的方法。existDocument(String index, String documents) 检查给定名称的索引中是否存在具有给定ID的文档的方法。getDocument(String index, String documents) 从给定名称的索引中检索具有给定ID的文档的方法。updateDocument(Dynamic dynamic, String index, String documents) 在给定名称的索引中更新具有给定ID的文档的方法。deleteDocument(String index, String documents) 从给定名称的索引中删除具有给定ID的文档的方法。bulkAddDocument(List dynamics) 在单个批处理中将多个文档添加到给定名称的索引的方法。searchDocument(String index) 基于搜索查询在给定名称的索引中搜索文档的方法。 import com.wangfugui.apprentice.common.util.ElasticSearchUtil; import com.wangfugui.apprentice.common.util.ResponseUtils; import com.wangfugui.apprentice.dao.domain.Dynamic; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController;import java.io.IOException; import java.util.List;/*** since JDK 1.8.0*/ RestController RequestMapping(/elasticSearch) Api(tags elasticSearch操作) public class ElasticSearchController {Autowiredprivate ElasticSearchUtil elasticSearchUtil;/**索引的创建*/PostMapping(/createIndex)ApiOperation(索引的创建)public ResponseUtils createIndex(RequestParam String index) throws IOException {return ResponseUtils.success(elasticSearchUtil.createIndex(index));}/**索引是否存在*/GetMapping(/existIndex)ApiOperation(索引是否存在)public ResponseUtils existIndex(RequestParam String index) throws IOException {return ResponseUtils.success(elasticSearchUtil.existIndex(index));}/**删除索引*/DeleteMapping(/deleteIndex)ApiOperation(删除索引)public ResponseUtils deleteIndex(RequestParam String index) throws IOException {return ResponseUtils.success(elasticSearchUtil.deleteIndex(index));}/**添加文档*/PostMapping(/addDocument)ApiOperation(添加文档随机id)public ResponseUtils addDocument(RequestBody Dynamic dynamic, RequestParam String index) throws IOException {return ResponseUtils.success(elasticSearchUtil.addDocument(dynamic,index));}/**添加文档*/PostMapping(/addDocument)ApiOperation(添加文档自定义id)public ResponseUtils addDocumentId(RequestBody Dynamic dynamic, RequestParam String index,RequestParam String id) throws IOException {return ResponseUtils.success(elasticSearchUtil.addDocumentId(dynamic,index,id));}/**文档是否存在*/GetMapping(/existDocument)ApiOperation(文档是否存在)public ResponseUtils existDocument(RequestParam String index, RequestParam String documents) throws IOException {return ResponseUtils.success(elasticSearchUtil.existDocument(index,documents));}/**获取文档*/GetMapping(/getDocument)ApiOperation(获取文档)public ResponseUtils getDocument(RequestParam String index, RequestParam String documents) throws IOException {return ResponseUtils.success(elasticSearchUtil.getDocument(index,documents));}/**修改文档*/ApiOperation(修改文档)PutMapping(/updateDocument)public ResponseUtils updateDocument(RequestBody Dynamic dynamic, RequestParam String index, RequestParam String documents) throws IOException {return ResponseUtils.success(elasticSearchUtil.updateDocument(dynamic,index,documents));}/**删除文档*/ApiOperation(删除文档)DeleteMapping(/deleteDocument)public ResponseUtils deleteDocument(RequestParam String index, RequestParam String documents) throws IOException {return ResponseUtils.success(elasticSearchUtil.deleteDocument(index,documents));}/**批量添加文档*/ApiOperation(批量添加文档)PostMapping(/bulkAddDocument)public ResponseUtils bulkAddDocument(RequestBody ListDynamic dynamics) throws IOException {return ResponseUtils.success(elasticSearchUtil.bulkAddDocument(dynamics));}/**查询文档*/ApiOperation(查询文档)GetMapping(/searchDocument)public ResponseUtils searchDocument(RequestParam String index) throws IOException {return ResponseUtils.success(elasticSearchUtil.searchDocument(index));}}第六步测试即可 成功
http://www.hkea.cn/news/14540916/

相关文章:

  • 如何购买域名建网站封面设计用什么软件做
  • 学网站制作多少钱一个完整的产品规划方案
  • 开个做网站的公司网站建设公司广告标题语
  • 那里可以免费做网站注册深圳公司流程和费用
  • 看怀集app下载深圳网站seo优化公司
  • 网站开发业务如何做一个营销型网站
  • 手表网站 欧米茄运用vs2010c 做网站
  • 邵阳竞价网站建设设计济南网站哪家做的好
  • 新闻类网站开发难点做药的常用网站
  • 沧州网站建设申梦施工企业安全形势分析会
  • 哈尔滨城市建设局网站wordpress商家展示主题
  • 宁波网站设计企业cms+wordpress+国内
  • 廊坊网站快速排名优化网站图片设置
  • 新加坡网站大全wordpress的用户分
  • 网站建设策划书前言注册安全工程师官网入口
  • a站是哪个app商城网站开发 价格
  • 响应式网站建设开发公司婚恋网站建设分析
  • 网站后台加密网站建设实训总结范文
  • 教育加盟网站建设嘉兴网站关键词推广
  • 建个网站需要服务器吗医院信息化建设网站
  • 珠宝网站设计外贸公司怎么接订单
  • 石家庄网站建设德信互联科技有限公司网页开发工具怎么打开
  • 做汤的网站有哪些福州服务类网站建设
  • 常州如何进行网站推广大型的平台类网站建设需要多少资金
  • 网站建设座谈会山西笑傲网站建设
  • 欧美个人网站招聘外包服务公司
  • 114百事通做网站600网络工程师网课
  • 德网站建设深圳形象设计公司
  • 开发施工建设网站审核最新项目网
  • 南宁市网站设计建设行业网站平台的瓶颈