Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sfewfsaf
spring-boot-examples
提交
4a3ce5a9
S
spring-boot-examples
项目概览
sfewfsaf
/
spring-boot-examples
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-boot-examples
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4a3ce5a9
编写于
4月 03, 2018
作者:
微笑很纯洁
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add spring-boot-elasticsearch
上级
d0c552b4
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
218 addition
and
0 deletion
+218
-0
spring-boot-elasticsearch/pom.xml
spring-boot-elasticsearch/pom.xml
+51
-0
spring-boot-elasticsearch/src/main/java/com/neo/ElasticsearchApplication.java
...earch/src/main/java/com/neo/ElasticsearchApplication.java
+12
-0
spring-boot-elasticsearch/src/main/java/com/neo/model/Customer.java
...t-elasticsearch/src/main/java/com/neo/model/Customer.java
+55
-0
spring-boot-elasticsearch/src/main/java/com/neo/repository/CustomerRepository.java
.../src/main/java/com/neo/repository/CustomerRepository.java
+17
-0
spring-boot-elasticsearch/src/main/resources/application.properties
...t-elasticsearch/src/main/resources/application.properties
+1
-0
spring-boot-elasticsearch/src/test/java/com/neo/ElasticsearchApplicationTests.java
.../src/test/java/com/neo/ElasticsearchApplicationTests.java
+18
-0
spring-boot-elasticsearch/src/test/java/com/neo/repository/CustomerRepositoryTest.java
.../test/java/com/neo/repository/CustomerRepositoryTest.java
+64
-0
未找到文件。
spring-boot-elasticsearch/pom.xml
0 → 100644
浏览文件 @
4a3ce5a9
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
com.neo
</groupId>
<artifactId>
spring-boot-elasticsearch
</artifactId>
<version>
1.0
</version>
<packaging>
jar
</packaging>
<name>
spring-boot-elasticsearch
</name>
<description>
Demo project for Spring Boot
</description>
<parent>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-parent
</artifactId>
<version>
2.0.0.RELEASE
</version>
</parent>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<java.version>
1.8
</java.version>
</properties>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-elasticsearch
</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>
spring-boot-elasticsearch/src/main/java/com/neo/ElasticsearchApplication.java
0 → 100644
浏览文件 @
4a3ce5a9
package
com.neo
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
@SpringBootApplication
public
class
ElasticsearchApplication
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
ElasticsearchApplication
.
class
,
args
);
}
}
spring-boot-elasticsearch/src/main/java/com/neo/model/Customer.java
0 → 100644
浏览文件 @
4a3ce5a9
package
com.neo.model
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.elasticsearch.annotations.Document
;
@Document
(
indexName
=
"customer"
,
type
=
"customer"
,
shards
=
1
,
replicas
=
0
,
refreshInterval
=
"-1"
)
public
class
Customer
{
@Id
private
String
id
;
private
String
userName
;
private
String
address
;
public
Customer
()
{
}
public
Customer
(
String
userName
,
String
address
)
{
this
.
userName
=
userName
;
this
.
address
=
address
;
}
public
String
getId
()
{
return
this
.
id
;
}
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
public
String
getUserName
()
{
return
userName
;
}
public
void
setUserName
(
String
userName
)
{
this
.
userName
=
userName
;
}
public
String
getAddress
()
{
return
address
;
}
public
void
setAddress
(
String
address
)
{
this
.
address
=
address
;
}
@Override
public
String
toString
()
{
return
String
.
format
(
"Customer[id=%s, userName='%s', address='%s']"
,
this
.
id
,
this
.
userName
,
this
.
address
);
}
}
spring-boot-elasticsearch/src/main/java/com/neo/repository/CustomerRepository.java
0 → 100644
浏览文件 @
4a3ce5a9
package
com.neo.repository
;
import
com.neo.model.Customer
;
import
org.springframework.data.elasticsearch.repository.ElasticsearchRepository
;
import
java.util.List
;
public
interface
CustomerRepository
extends
ElasticsearchRepository
<
Customer
,
String
>
{
public
Customer
findByUserName
(
String
userName
);
public
int
deleteByUserName
(
String
userName
);
public
List
<
Customer
>
findByAddress
(
String
address
);
}
spring-boot-elasticsearch/src/main/resources/application.properties
0 → 100644
浏览文件 @
4a3ce5a9
spring.data.elasticsearch.cluster-nodes
=
localhost:9300
\ No newline at end of file
spring-boot-elasticsearch/src/test/java/com/neo/ElasticsearchApplicationTests.java
0 → 100644
浏览文件 @
4a3ce5a9
package
com.neo
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.context.junit4.SpringRunner
;
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
public
class
ElasticsearchApplicationTests
{
@Test
public
void
contextLoads
()
{
System
.
out
.
println
(
"Spring Boot Test"
);
}
}
spring-boot-elasticsearch/src/test/java/com/neo/repository/CustomerRepositoryTest.java
0 → 100644
浏览文件 @
4a3ce5a9
package
com.neo.repository
;
import
com.neo.model.Customer
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringRunner
;
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
public
class
CustomerRepositoryTest
{
@Autowired
private
CustomerRepository
repository
;
@Test
public
void
saveCustomers
()
{
repository
.
save
(
new
Customer
(
"Alice"
,
"北京"
));
repository
.
save
(
new
Customer
(
"Bob"
,
"北京"
));
repository
.
save
(
new
Customer
(
"neo"
,
"西安"
));
repository
.
save
(
new
Customer
(
"summer"
,
"烟台"
));
}
@Test
public
void
deleteCustomers
()
{
// repository.deleteAll();
repository
.
deleteByUserName
(
"neo"
);
}
@Test
public
void
updateCustomers
()
{
Customer
customer
=
repository
.
findByUserName
(
"summer"
);
System
.
out
.
println
(
customer
);
customer
.
setAddress
(
"北京市海淀区西直门"
);
repository
.
save
(
customer
);
Customer
xcustomer
=
repository
.
findByUserName
(
"summer"
);
System
.
out
.
println
(
xcustomer
);
}
@Test
public
void
fetchAllCustomers
()
{
System
.
out
.
println
(
"Customers found with findAll():"
);
System
.
out
.
println
(
"-------------------------------"
);
for
(
Customer
customer
:
repository
.
findAll
())
{
System
.
out
.
println
(
customer
);
}
System
.
out
.
println
();
}
@Test
public
void
fetchIndividualCustomers
()
{
System
.
out
.
println
(
"Customer found with findByUserName('summer'):"
);
System
.
out
.
println
(
"--------------------------------"
);
System
.
out
.
println
(
repository
.
findByUserName
(
"summer"
));
System
.
out
.
println
(
"Customers found with findByAddress(\"北京\"):"
);
System
.
out
.
println
(
"--------------------------------"
);
for
(
Customer
customer
:
repository
.
findByAddress
(
"北京"
))
{
System
.
out
.
println
(
customer
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录