SpringBoot2.0之整合ElasticSearch
就类比数据库到时候去实现
服务器端配置 集群名字 与yml名字一致

pom:
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.toov5</groupId>
<artifactId>springboot-es</artifactId>
<version>0.0.1-SNAPSHOT</version> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- springboot 整合es -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies> </project>
项目结构:

Entity:
package com.toov5.entity; import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document; import lombok.Data; @Document(indexName="toov5",type="user") //索引的名字 类型
@Data
public class UserEntity {
@Id
private String id;
private String name;
private Integer age;
private Integer sex;
}
Dao:
package com.toov5.dao;
import org.springframework.data.repository.CrudRepository;
import com.toov5.entity.UserEntity;
public interface UserDao extends CrudRepository<UserEntity, String> {
}
Controller:
package com.toov5.controller; import java.util.Optional; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import com.toov5.dao.UserDao;
import com.toov5.entity.UserEntity; @RestController
public class EsController { @Autowired
private UserDao userDao; //添加文档
@RequestMapping("/addUser")
public UserEntity addUser(@RequestBody UserEntity userEntity) {
return userDao.save(userEntity);
} //查询文档
@RequestMapping("/findById")
public Optional<UserEntity> findById(String id) {
return userDao.findById(id);
} }
成功:

查看:

查询:

SpringBoot2.0之整合ElasticSearch的更多相关文章
- SpringBoot2.0之整合Kafka
maven依赖: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www. ...
- SpringBoot2.0之整合Apollo
Spring Boot客户端对接阿波罗服务器端 核心源码都在这个压缩包里面 封装好了环境 运行shell脚本就ok了 下面进入到本地maven仓库: 远程仓库apollo的jar包 只能打包到本地或者 ...
- SpringBoot2.0之整合ActiveMQ(发布订阅模式)
发布订阅模式与前面的点对点模式很类似,简直一毛一样 注意:发布订阅模式 先启动消费者 公用pom: <project xmlns="http://maven.apache.org/PO ...
- SpringBoot2.0之整合ActiveMQ(点对点模式)
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
- SpringBoot2.0之整合Dubbo
Dubbo支持协议 Dubbo支持dubbo.rmi.hessian.http.webservice.thrift.redis等多种协议,但是Dubbo官网是推荐我们使用Dubbo协议的. Sprin ...
- 基于 SpringBoot2.0+优雅整合 SpringBoot+Mybatis
SpringBoot 整合 Mybatis 有两种常用的方式,一种就是我们常见的 xml 的方式 ,还有一种是全注解的方式.我觉得这两者没有谁比谁好,在 SQL 语句不太长的情况下,我觉得全注解的方式 ...
- springboot2.0 Mybatis 整合
原文:https://blog.csdn.net/Winter_chen001/article/details/80010967 环境/版本一览: 开发工具:Intellij IDEA 2017.1. ...
- 每天学点SpringCloud(一):使用SpringBoot2.0.3整合SpringCloud
最近开始学习SpringCloud,在此把我学习的过程记录起来,跟大家分享一下,一起学习.想学习SpringCloud的同学赶快上车吧. 本次学习使用得SpringBoot版本为2.0.3.RELEA ...
- springboot2.0+dubbo整合分布式服务发布和调用
最近项目上要对以前的老项目做分布式的整改,因此我专门花了点时间研究下当前比较热门的dubbo和springboot结合使用,以前使用过dubbo,但是没有与springboot结合过,在网上查了点资料 ...
随机推荐
- [Go语言]从Docker源码学习Go——init()方法和identifier首字母大小写区分
init()方法 如果想在一个go文件里,进行一些初始化的工作,可以把代码放到init()方法中. init()方法先被执行. func init() { // initialization of p ...
- delphi ----日期控件运用,日期问题,日期时间比较
一.日期控件 1.DateTimePicker 1)只显示年月 DateMode:dmUpDown format:yyyy-MM 2)将DateTimePicker的Format属性中加入日期格式设成 ...
- python迭代器、生成器、yield和xrange
https://blog.csdn.net/u010138758/article/details/56291013
- Qt 打印机支持模块
Qt 打印支持 Qt为打印提供广泛的跨平台支持.使用每个平台上的打印系统,Qt应用程序可以打印到连接的打印机,并通过网络打印到远程打印机.Qt的打印系统还支持PDF文件生成,为基本的报告生成设施奠定了 ...
- .net ASPxGridView 使用手记
统计汇总功能: TotalSummary属性:此属性必须设置KeyFieldName属性:Settings中的ShowFooter属性设置为True. DisplayFormat:同.net中的Str ...
- Selenium定位不到指定元素原因之iframe(unable to locate element)
浏览过程中,图片中的内容可能太小,无法看清,可以>右键>在新标签中打开 Outline 项目原因,需要用selenium实现模拟登陆.模拟上传文件,自然就需要模拟点击[上传]按钮: 模拟点 ...
- django博客项目6:Django Admin 后台发布文章
在此之前我们完成了 Django 博客首页视图的编写,我们希望首页展示发布的博客文章列表,但是它却抱怨:暂时还没有发布的文章!如它所言,我们确实还没有发布任何文章,本节我们将使用 Django 自带的 ...
- python进程间数据不共享(示例演示)
import multiprocessing data_list = [] def task(arg): data_list.append(arg) print(data_list) def run( ...
- 【我的Android进阶之旅】解决strings.xml格式化占位符错误: Multiple substitutions specified in non-positional format
今天有一个Android新手使用strings.xml进行格式化的时候报了占位符错误, Multiple substitutions specified in non-positional forma ...
- RS232串口通信
RS232串口经常使用在PC机与FPGA通信中,用于两者之间的数据传输,因为UART协议简单.易实现,故经常使用. DB9接口只需要使用3根线,RXD(2).TXD(3)和GND(5),如下图所示.而 ...