forked from yudaocode/SpringBoot-Labs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
YunaiV
committed
Jan 3, 2020
1 parent
a94b3ad
commit cbb6c3e
Showing
25 changed files
with
464 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ hs_err_pid* | |
SpringBoot-Labs.ipr | ||
SpringBoot-Labs.iws | ||
target/** | ||
*.lst | ||
*.iml | ||
*ipr | ||
*.iws | ||
*.iws |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?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"> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.2.2.RELEASE</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>lab-39-elasticsearch</artifactId> | ||
|
||
<dependencies> | ||
<!-- 实现对 SpringMVC 的自动化配置 --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
|
||
<!-- 自动化配置 Spring Data Elasticsearch --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-elasticsearch</artifactId> | ||
<version>2.2.1.RELEASE</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
13 changes: 13 additions & 0 deletions
13
...ch/src/main/java/cn/iocoder/springboot/lab39/skywalkingdemo/ElasticsearchApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package cn.iocoder.springboot.lab39.skywalkingdemo; | ||
|
||
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); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
...h/src/main/java/cn/iocoder/springboot/lab39/skywalkingdemo/controller/DemoController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package cn.iocoder.springboot.lab39.skywalkingdemo.controller; | ||
|
||
import cn.iocoder.springboot.lab39.skywalkingdemo.dataobject.ESUserDO; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.mongodb.core.MongoTemplate; | ||
import org.springframework.data.mongodb.core.query.Criteria; | ||
import org.springframework.data.mongodb.core.query.Query; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/demo") | ||
public class DemoController { | ||
|
||
@Autowired | ||
private MongoTemplate mongoTemplate; | ||
|
||
@GetMapping("/mongodb") | ||
public String mysql() { | ||
this.findById(1); | ||
return "mongodb"; | ||
} | ||
|
||
public ESUserDO findById(Integer id) { | ||
return mongoTemplate.findOne(new Query(Criteria.where("_id").is(id)), ESUserDO.class); | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
...csearch/src/main/java/cn/iocoder/springboot/lab39/skywalkingdemo/dataobject/ESUserDO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package cn.iocoder.springboot.lab39.skywalkingdemo.dataobject; | ||
|
||
import java.util.Date; | ||
|
||
@Document(indexName = "user", // 索引名 | ||
type = "user", // 类型。未来的版本即将废弃 | ||
shards = 1, // 默认索引分区数 | ||
replicas = 0, // 每个分区的备份数 | ||
refreshInterval = "-1" // 刷新间隔 | ||
) | ||
public class ESUserDO { | ||
|
||
@Id | ||
private Integer id; | ||
/** | ||
* 账号 | ||
*/ | ||
private String username; | ||
/** | ||
* 密码 | ||
*/ | ||
private String password; | ||
/** | ||
* 创建时间 | ||
*/ | ||
private Date createTime; | ||
|
||
@Override | ||
public String toString() { | ||
return "UserDO{" + | ||
"id=" + id + | ||
", username='" + username + '\'' + | ||
", password='" + password + '\'' + | ||
", createTime=" + createTime + | ||
'}'; | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
lab-39/lab-39-elasticsearch/src/main/resources/application.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
server: | ||
port: 8079 | ||
|
||
spring: | ||
data: | ||
# Elasticsearch 配置项 | ||
elasticsearch: | ||
cluster-name: elasticsearch # 集群名 | ||
cluster-nodes: 127.0.0.1:9300 # 集群节点 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?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"> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.2.2.RELEASE</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>lab-39-mongodb</artifactId> | ||
|
||
<dependencies> | ||
<!-- 实现对 SpringMVC 的自动化配置 --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
|
||
<!-- 自动化配置 Spring Data Mongodb --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-mongodb</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
13 changes: 13 additions & 0 deletions
13
...-mongodb/src/main/java/cn/iocoder/springboot/lab39/skywalkingdemo/MongoDBApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package cn.iocoder.springboot.lab39.skywalkingdemo; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class MongoDBApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(MongoDBApplication.class, args); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
...b/src/main/java/cn/iocoder/springboot/lab39/skywalkingdemo/controller/DemoController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package cn.iocoder.springboot.lab39.skywalkingdemo.controller; | ||
|
||
import cn.iocoder.springboot.lab39.skywalkingdemo.dataobject.UserDO; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.mongodb.core.MongoTemplate; | ||
import org.springframework.data.mongodb.core.query.Criteria; | ||
import org.springframework.data.mongodb.core.query.Query; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/demo") | ||
public class DemoController { | ||
|
||
@Autowired | ||
private MongoTemplate mongoTemplate; | ||
|
||
@GetMapping("/mongodb") | ||
public String mysql() { | ||
this.findById(1); | ||
return "mongodb"; | ||
} | ||
|
||
public UserDO findById(Integer id) { | ||
return mongoTemplate.findOne(new Query(Criteria.where("_id").is(id)), UserDO.class); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
...9-mongodb/src/main/java/cn/iocoder/springboot/lab39/skywalkingdemo/dataobject/UserDO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package cn.iocoder.springboot.lab39.skywalkingdemo.dataobject; | ||
|
||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.mongodb.core.mapping.Document; | ||
|
||
import java.util.Date; | ||
|
||
/** | ||
* 用户 DO | ||
*/ | ||
@Document(collection = "User") | ||
public class UserDO { | ||
|
||
@Id | ||
private Integer id; | ||
/** | ||
* 账号 | ||
*/ | ||
private String username; | ||
/** | ||
* 密码 | ||
*/ | ||
private String password; | ||
/** | ||
* 创建时间 | ||
*/ | ||
private Date createTime; | ||
|
||
@Override | ||
public String toString() { | ||
return "UserDO{" + | ||
"id=" + id + | ||
", username='" + username + '\'' + | ||
", password='" + password + '\'' + | ||
", createTime=" + createTime + | ||
'}'; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
server: | ||
port: 8079 | ||
|
||
spring: | ||
data: | ||
# MongoDB 配置项,对应 MongoProperties 类 | ||
mongodb: | ||
host: 127.0.0.1 | ||
port: 27017 | ||
database: yourdatabase | ||
username: test01 | ||
password: password01 | ||
# 上述属性,也可以只配置 uri |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
server: | ||
port: 8079 | ||
|
||
spring: | ||
data: | ||
# MongoDB 配置项,对应 MongoProperties 类 | ||
mongodb: | ||
host: 127.0.0.1 | ||
port: 27017 | ||
database: yourdatabase | ||
username: test01 | ||
password: password01 | ||
# 上述属性,也可以只配置 uri |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?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"> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.2.2.RELEASE</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>lab-39-mysql</artifactId> | ||
|
||
<dependencies> | ||
<!-- 实现对 SpringMVC 的自动化配置 --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
|
||
<!-- 实现对数据库连接池的自动化配置 --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-jdbc</artifactId> | ||
</dependency> | ||
<dependency> <!-- 本示例,我们使用 MySQL --> | ||
<groupId>mysql</groupId> | ||
<artifactId>mysql-connector-java</artifactId> | ||
<version>5.1.46</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
13 changes: 13 additions & 0 deletions
13
...b-39-mysql/src/main/java/cn/iocoder/springboot/lab39/skywalkingdemo/MySQLApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package cn.iocoder.springboot.lab39.skywalkingdemo; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class MySQLApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(MySQLApplication.class, args); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
...l/src/main/java/cn/iocoder/springboot/lab39/skywalkingdemo/controller/DemoController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package cn.iocoder.springboot.lab39.skywalkingdemo.controller; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.jdbc.core.BeanPropertyRowMapper; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/demo") | ||
public class DemoController { | ||
|
||
@Autowired | ||
private JdbcTemplate template; | ||
|
||
@GetMapping("/mysql") | ||
public String mysql() { | ||
this.selectById(1); | ||
return "mysql"; | ||
} | ||
|
||
public Object selectById(Integer id) { | ||
return template.queryForObject("SELECT id, username, password FROM t_user WHERE id = ?", | ||
new BeanPropertyRowMapper<>(Object.class), // 结果转换成对应的对象。Object 理论来说是 UserDO.class ,这里偷懒了。 | ||
id); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
server: | ||
port: 8079 | ||
|
||
spring: | ||
# datasource 数据源配置内容 | ||
datasource: | ||
url: jdbc:mysql://127.0.0.1:3306/lab-39-mysql?useSSL=false&useUnicode=true&characterEncoding=UTF-8 | ||
driver-class-name: com.mysql.jdbc.Driver | ||
username: root | ||
password: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
server: | ||
port: 8079 | ||
|
||
spring: | ||
# datasource 数据源配置内容 | ||
datasource: | ||
url: jdbc:mysql://127.0.0.1:3306/lab-39-mysql?useSSL=false&useUnicode=true&characterEncoding=UTF-8 | ||
driver-class-name: com.mysql.jdbc.Driver | ||
username: root | ||
password: |
Oops, something went wrong.