Skip to content

Commit 653a27a

Browse files
author
YunaiV
committed
增加 spring boot + feign 示例
1 parent 85f3f58 commit 653a27a

File tree

6 files changed

+145
-0
lines changed

6 files changed

+145
-0
lines changed

lab-58/lab-58-user-service/pom.xml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>lab-58</artifactId>
7+
<groupId>cn.iocoder.springboot.labs</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>lab-58-user-service</artifactId>
13+
14+
<properties>
15+
<maven.compiler.target>1.8</maven.compiler.target>
16+
<maven.compiler.source>1.8</maven.compiler.source>
17+
<spring.boot.version>2.2.4.RELEASE</spring.boot.version>
18+
</properties>
19+
20+
<dependencyManagement>
21+
<dependencies>
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-starter-parent</artifactId>
25+
<version>${spring.boot.version}</version>
26+
<type>pom</type>
27+
<scope>import</scope>
28+
</dependency>
29+
</dependencies>
30+
</dependencyManagement>
31+
32+
<dependencies>
33+
<!-- 引入 SpringMVC 相关依赖,并实现对其的自动配置 -->
34+
<dependency>
35+
<groupId>org.springframework.boot</groupId>
36+
<artifactId>spring-boot-starter-web</artifactId>
37+
</dependency>
38+
</dependencies>
39+
40+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package cn.iocoder.springboot.lab58.userservice;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class UserServiceApplication {
8+
9+
public static void main(String[] args) {
10+
// 设置端口
11+
System.setProperty("server.port", "18080");
12+
13+
// 应用启动
14+
SpringApplication.run(UserServiceApplication.class, args);
15+
}
16+
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package cn.iocoder.springboot.lab58.userservice.controller;
2+
3+
import cn.iocoder.springboot.lab58.userservice.response.UserResponse;
4+
import org.springframework.web.bind.annotation.GetMapping;
5+
import org.springframework.web.bind.annotation.RequestMapping;
6+
import org.springframework.web.bind.annotation.RequestParam;
7+
import org.springframework.web.bind.annotation.RestController;
8+
9+
import java.util.ArrayList;
10+
import java.util.List;
11+
12+
@RestController
13+
@RequestMapping("/user")
14+
public class UserController {
15+
16+
@GetMapping("/get")
17+
public UserResponse get(@RequestParam("id") Integer id) {
18+
return new UserResponse().setId(id)
19+
.setName("昵称:" + id).setGender(id % 2 == 0 ? 1 : 2);
20+
}
21+
22+
@GetMapping("/list")
23+
public List<UserResponse> list(@RequestParam("name") String name,
24+
@RequestParam("gender") Integer gender) {
25+
List<UserResponse> users = new ArrayList<>();
26+
for (int id = 1; id <= 3; id++) {
27+
users.add(new UserResponse().setId(id)
28+
.setName(name).setGender(gender));
29+
}
30+
return users;
31+
}
32+
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package cn.iocoder.springboot.lab58.userservice.response;
2+
3+
public class UserResponse {
4+
5+
private Integer id;
6+
private String name;
7+
private Integer gender;
8+
9+
public Integer getId() {
10+
return id;
11+
}
12+
13+
public UserResponse setId(Integer id) {
14+
this.id = id;
15+
return this;
16+
}
17+
18+
public String getName() {
19+
return name;
20+
}
21+
22+
public UserResponse setName(String name) {
23+
this.name = name;
24+
return this;
25+
}
26+
27+
public Integer getGender() {
28+
return gender;
29+
}
30+
31+
public UserResponse setGender(Integer gender) {
32+
this.gender = gender;
33+
return this;
34+
}
35+
}

lab-58/pom.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>labs-parent</artifactId>
7+
<groupId>cn.iocoder.springboot.labs</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>lab-58</artifactId>
13+
<packaging>pom</packaging>
14+
15+
<modules>
16+
<module>lab-58-user-service</module>
17+
</modules>
18+
19+
</project>

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
<!-- <module>labx-22</module>-->
9494
<!-- <module>labx-23</module>-->
9595
<!-- <module>lab-57</module>-->
96+
<module>lab-58</module>
9697
</modules>
9798

9899
</project>

0 commit comments

Comments
 (0)