Springboot demo
Highly recommended
This demo demonstrates the seamless integration of Easy-Es with Springboot project, it is highly recommended to download it first and run it directly in your local area to avoid stepping on the pit when integrating it yourself due to springboot and other version compatibility issues.
Download Demo address: ✔ Gitee (opens new window) | ✔ Github (opens new window)
# Introduction
# 1. Project structure
This demo omits the service layer for demonstration purposes.
# 2.Pom
<?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.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>ee-use</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>ee-use</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.dromara.easy-es</groupId>
<artifactId>easy-es-boot-starter</artifactId>
<version>${Latest version}</version>
</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>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
✨Latest Version Latest Version: (https://search .maven.org/search?q=g:io.github.xpc1024%20a:easy-*)
Special Note
The latest version of the current release Latest version please see the above figure to get, the actual fill is the specific version number numbers, such as 2.0.0, not Latest version!!!!
In addition, because springboot built-in associated es version, different springboot version will lead to the introduction of the actual project es dependency version is too low or too high, Many users have stepped into the pit of compatibility problems caused by conflicting dependencies, so we would like to remind you that if the actual es version that your project depends on is not 7.14.0 version, we strongly recommend that you show the specified es dependency jar package version for 7.14.0, and we use the underlying es dependency version to maintain consistency, so the best compatibility, It is not easy to step in the hole. The reason for the underlying 7.14.0 is also after much research, choose a stable version without security vulnerabilities, by Murphy scan the version is safe and reliable. As for the ES client version, 7.10+ tested compatibility are very good, the dependency of the jar package version and the client version does not matter, the focus is on the dependency of the Jar version.
# 3. core code
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class TestUseEeController {
private final DocumentMapper documentMapper;
@GetMapping("/createIndex")
public Boolean createIndex() {
// 1.initialize-> create index (like a table in mysql.)
return documentMapper.createIndex();
}
@GetMapping("/insert")
public Integer insert() {
// initialize -> add data
Document document = new Document();
document.setTitle("Old Man");
document.setContent("push*technical overkill");
return documentMapper.insert(document);
}
@GetMapping("/search")
public List<Document> search() {
// query out all the title of the old man's document list
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
wrapper.eq(Document::getTitle, "Old Man");
return documentMapper.selectList(wrapper);
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 4. Start and use
# a. Add configuration information
easy-es:
enable: true # default is true, if false, then the framework is not enabled
address : 127.0.0.0:9200 # fill in the address of your es connection
# username: set to fill in, not required
# password: set to fill in, not required
2
3
4
5
# b. Start the Project
Start the project with your IDE
# c. Use
http://localhost:8080/createIndex (opens new window) (create index)
http://localhost:8080/insert (opens new window) ( insert data)
http://localhost:8080/search (opens new window) ( query)
Effect:
# 5. Conclusion
At this point, you have already experienced the basic functions of Easy-Es, if you feel that the experience is still good and want to experience more powerful functions, then continue to read on!