File tree 6 files changed +145
-0
lines changed
src/main/java/cn/iocoder/springboot/lab58/userservice 6 files changed +145
-0
lines changed Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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 number Diff line number Diff line change
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 number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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 >
Original file line number Diff line number Diff line change 93
93
<!-- <module>labx-22</module>-->
94
94
<!-- <module>labx-23</module>-->
95
95
<!-- <module>lab-57</module>-->
96
+ <module >lab-58</module >
96
97
</modules >
97
98
98
99
</project >
You can’t perform that action at this time.
0 commit comments