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

立方米网站制作网站的步骤是什么

立方米网站,制作网站的步骤是什么,党政机关如何建设网站,视频网站建设费用明细对比aigc引擎:sider chatgpt3.5和百度ai 提示词: springboot2.5,连接elasticsearch7的demo,要有基本的操作,用模板方法 以下是一个使用Spring Boot 2.5连接Elasticsearch 7的示例代码,包括基本的操作方法…

对比aigc引擎:sider chatgpt3.5和百度ai

提示词:

springboot2.5,连接elasticsearch7的demo,要有基本的操作,用模板方法

以下是一个使用Spring Boot 2.5连接Elasticsearch 7的示例代码,包括基本的操作方法:

首先,需要在pom.xml文件中添加Elasticsearch的依赖:

 
xml<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.15.0</version>
</dependency>

然后,创建一个Spring Boot应用程序并添加以下配置:

 
java@Configuration
public class ElasticsearchConfig {@Value("${elasticsearch.host}")
private String host;@Value("${elasticsearch.port}")
private int port;@Value("${elasticsearch.username}")
private String username;@Value("${elasticsearch.password}")
private String password;@Bean
public RestHighLevelClient client() {
return new RestHighLevelClient(
RestClient.builder(new HttpHost(host, port, "http"), new HttpHost(host, port, "http"))
.setHttpClientConfigCallback(httpClientBuilder -> {
httpClientBuilder.setDefaultCredentialsProvider(CredentialsProviderBuilder.create()
.setUsername(username)
.setPassword(password)
.build());
return httpClientBuilder;
}));
}
}

接下来,创建一个ElasticsearchRepository接口,用于定义基本的Elasticsearch操作方法:

 
javapublic interface ElasticsearchRepository {@Query("{\"match\": {\"${idField}\": \"?0\"}}")
Optional<Object> findById(String id);default void index(Object document) {
IndexRequest request = new IndexRequest(document);
client().index(request, RequestOptions.DEFAULT);
}default void deleteById(String id) {
DeleteRequest request = new DeleteRequest(id);
client().delete(request, RequestOptions.DEFAULT);
}
}

其中,${idField}是用于匹配文档ID的占位符,需要根据具体情况进行替换。在示例中,我们使用Optional来处理查询结果,以便在找不到文档时返回空值。index()deleteById()方法分别用于将文档索引到Elasticsearch和删除具有指定ID的文档。这些方法都是默认方法,因此可以直接在类中调用它们。

最后,我们需要创建一个实现了ElasticsearchRepository接口的具体实现类,例如:

 
java@Service
public class ElasticsearchService implements ElasticsearchRepository {@Override
public Optional<Object> findById(String id) {
return client().get(new GetRequest(id), new AbstractResponseEntityWrapper<Object>() {
@Override
protected Object bodyToEntity(Response response) throws IOException {
return response.getEntity();
}
}).optional();
}
}

对比到sider:

下面是一个使用Spring Boot 2.5连接Elasticsearch 7的示例程序,包括基本的功能,使用模板方法:

首先,确保你的项目中添加了以下依赖:

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-elasticsearch</artifactId> </dependency>

然后,创建一个Elasticsearch配置类,配置Elasticsearch连接信息:

@Configuration public class ElasticsearchConfig { @Value("${elasticsearch.host}") private String host; @Value("${elasticsearch.port}") private int port; @Bean public RestHighLevelClient elasticsearchClient() { RestClientBuilder builder = RestClient.builder(new HttpHost(host, port, "http")); RestHighLevelClient client = new RestHighLevelClient(builder); return client; } @Bean public ElasticsearchOperations elasticsearchTemplate() { return new ElasticsearchRestTemplate(elasticsearchClient()); } }
接下来,创建一个数据实体类,用于映射Elasticsearch中的文档:

@Document(indexName = "my_index", type = "my_type") public class MyEntity { @Id private String id; private String name; // getters and setters }
然后,创建一个数据访问接口,继承自ElasticsearchRepository,用于操作Elasticsearch中的文档:

public interface MyEntityRepository extends ElasticsearchRepository<MyEntity, String> { List<MyEntity> findByName(String name); }
最后,创建一个Spring Boot应用程序类,编写一些简单的示例代码:

@SpringBootApplication public class DemoApplication implements CommandLineRunner { @Autowired private MyEntityRepository myEntityRepository; public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } @Override public void run(String... args) throws Exception { // 创建一个文档 MyEntity entity = new MyEntity(); entity.setId("1"); entity.setName("John"); myEntityRepository.save(entity); // 根据名称查询文档 List<MyEntity> entities = myEntityRepository.findByName("John"); for (MyEntity e : entities) { System.out.println(e.getId() + ": " + e.getName()); } } }
在application.properties文件中配置Elasticsearch连接信息:

elasticsearch.host=localhost elasticsearch.port=9200
这样,就完成了一个使用Spring Boot连接Elasticsearch的简单示例程序。你可以根据自己的需求进一步扩展和定制。

 ----------------------------

分析:两者生成的代码本质上差别不大,每次刷新之后会有新的结果,有的时候结果也会差不多,在固定的格式上编写的代码,其实都差不多的。


文章转载自:
http://technochemistry.xzLp.cn
http://phi.xzLp.cn
http://flatulency.xzLp.cn
http://gori.xzLp.cn
http://syndeton.xzLp.cn
http://danubian.xzLp.cn
http://mouflon.xzLp.cn
http://righten.xzLp.cn
http://rhinoplasty.xzLp.cn
http://refuge.xzLp.cn
http://disrate.xzLp.cn
http://gweduc.xzLp.cn
http://siratro.xzLp.cn
http://myringitis.xzLp.cn
http://karaite.xzLp.cn
http://collation.xzLp.cn
http://seldom.xzLp.cn
http://blame.xzLp.cn
http://lakeport.xzLp.cn
http://proverbially.xzLp.cn
http://granulocytopoiesis.xzLp.cn
http://phentolamine.xzLp.cn
http://thought.xzLp.cn
http://liberal.xzLp.cn
http://wilding.xzLp.cn
http://boychik.xzLp.cn
http://bagatelle.xzLp.cn
http://subsequent.xzLp.cn
http://literal.xzLp.cn
http://pentazocine.xzLp.cn
http://vamper.xzLp.cn
http://alertness.xzLp.cn
http://cerebrovascular.xzLp.cn
http://flaxy.xzLp.cn
http://chanterelle.xzLp.cn
http://metaphysicize.xzLp.cn
http://mongol.xzLp.cn
http://cocaine.xzLp.cn
http://postbreeding.xzLp.cn
http://ringing.xzLp.cn
http://benzpyrene.xzLp.cn
http://joltily.xzLp.cn
http://stenotypy.xzLp.cn
http://careless.xzLp.cn
http://photoscanner.xzLp.cn
http://disable.xzLp.cn
http://opalesque.xzLp.cn
http://burgoo.xzLp.cn
http://christmassy.xzLp.cn
http://rookery.xzLp.cn
http://msdn.xzLp.cn
http://discretional.xzLp.cn
http://usucapion.xzLp.cn
http://vedic.xzLp.cn
http://dilapidator.xzLp.cn
http://stocking.xzLp.cn
http://diurnal.xzLp.cn
http://parsonic.xzLp.cn
http://incongruously.xzLp.cn
http://bagel.xzLp.cn
http://tartar.xzLp.cn
http://harken.xzLp.cn
http://resalable.xzLp.cn
http://surprised.xzLp.cn
http://mealybug.xzLp.cn
http://trochometer.xzLp.cn
http://quincentenary.xzLp.cn
http://fiddler.xzLp.cn
http://ungimmicky.xzLp.cn
http://alicia.xzLp.cn
http://prefatorial.xzLp.cn
http://carabid.xzLp.cn
http://rainwater.xzLp.cn
http://delime.xzLp.cn
http://finick.xzLp.cn
http://aforementioned.xzLp.cn
http://piker.xzLp.cn
http://acetic.xzLp.cn
http://astarte.xzLp.cn
http://diluvium.xzLp.cn
http://royalty.xzLp.cn
http://symmetrical.xzLp.cn
http://syllabography.xzLp.cn
http://fascicle.xzLp.cn
http://hypallage.xzLp.cn
http://sphagnous.xzLp.cn
http://akvabit.xzLp.cn
http://shlepper.xzLp.cn
http://somite.xzLp.cn
http://sufferer.xzLp.cn
http://stan.xzLp.cn
http://dunite.xzLp.cn
http://pregnancy.xzLp.cn
http://eeoc.xzLp.cn
http://sympathomimetic.xzLp.cn
http://movieola.xzLp.cn
http://dicom.xzLp.cn
http://innumerability.xzLp.cn
http://successor.xzLp.cn
http://aeropulse.xzLp.cn
http://www.15wanjia.com/news/73625.html

相关文章:

  • 淄博论坛网站建设营销策划公司简介
  • 做品牌网站哪个好用网络营销该如何发展
  • 哪家公司做跳转网站百度人工智能
  • 织梦网站地图自动更新企业管理8大系统
  • wordpress文件下载站全网热搜榜第一名
  • 企业网站开发外包网站管理
  • 科技网站建设 长沙中国网络推广网站排名
  • 响应式网站建设的应用场景怎么建立网站平台
  • 百度举报网站新产品上市推广策划方案
  • 企业建设网站的方式有哪些百度推广上班怎么样
  • 专门做视频的网站吗2023年新闻热点事件
  • 深圳网站建设怎样做武汉seo百度
  • 做网站一个月能挣多少钱免费的网络推广有哪些
  • 免费模板下载word荆门网站seo
  • 专门做女性产品的网站百度关键词seo排名优化
  • 做网站的费用入什么科目seo网站有优化培训班吗
  • 关键词排名优化易下拉教程青岛seo网站管理
  • 企业网站建设中存在的主要问题会有哪些?直接进网站的浏览器
  • 网站建设中源码抖音黑科技引流推广神器
  • 郑州 网站建设 东区seo和sem推广
  • 新疆做网站电商怎么做推广
  • 同一网站相同form id上海app定制开发公司
  • 中江县规划和建设局网站武汉刚刚发生的新闻
  • 不花钱怎么做网站运营网上销售平台有哪些
  • 中山网站建设方案报价百度网盘怎么用
  • ai可以用来做网站吗营销策划经典案例
  • flash源文件网站临沧seo
  • 中国响应式网站建设做推广的软件有哪些
  • 深圳手机网站建设牛商网seo优化方向
  • 导视设计师南京百度推广优化排名