example changed

This commit is contained in:
many2many 2024-11-01 09:24:55 +08:00
parent 9fb8b80bc6
commit 95680afb74
3 changed files with 75 additions and 0 deletions

View File

@ -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;
}
}

View File

@ -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<User> index() {
return userService.getUsers();
}
}

View File

@ -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<User> getUsers(){
List<User> 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;
}
}