diff --git a/examples/chapter05/spring-boot-web-demo/src/main/java/com/lk/demo/User.java b/examples/chapter05/spring-boot-web-demo/src/main/java/com/lk/demo/User.java new file mode 100644 index 0000000..320aa80 --- /dev/null +++ b/examples/chapter05/spring-boot-web-demo/src/main/java/com/lk/demo/User.java @@ -0,0 +1,37 @@ +package com.lk.demo; + +public class User { + private String name; + private String email; + private String phone; + + public User(String name, String email, String phone) { + this.name = name; + this.email = email; + this.phone = phone; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } +} diff --git a/examples/chapter05/spring-boot-web-demo/src/main/java/com/lk/demo/UserController.java b/examples/chapter05/spring-boot-web-demo/src/main/java/com/lk/demo/UserController.java new file mode 100644 index 0000000..1132274 --- /dev/null +++ b/examples/chapter05/spring-boot-web-demo/src/main/java/com/lk/demo/UserController.java @@ -0,0 +1,21 @@ +package com.lk.demo; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@RequestMapping("/users") +public class UserController { + + @Autowired + private UserService userService; + + @GetMapping("") + public List index() { + return userService.getUsers(); + } +} diff --git a/examples/chapter05/spring-boot-web-demo/src/main/java/com/lk/demo/UserService.java b/examples/chapter05/spring-boot-web-demo/src/main/java/com/lk/demo/UserService.java new file mode 100644 index 0000000..6898e82 --- /dev/null +++ b/examples/chapter05/spring-boot-web-demo/src/main/java/com/lk/demo/UserService.java @@ -0,0 +1,17 @@ +package com.lk.demo; + +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +@Service +public class UserService { + public List getUsers(){ + List users = new ArrayList<>(); + users.add(new User("mike","mike@mail.com", "188111111")); + users.add(new User("john","john@mail.com", "133222222")); + users.add(new User("tom","tom@mail.com", "199222222")); + return users; + } +}