init

Change-Id: I42ce9491614d73adf28295781b319809d1969b82
diff --git a/src/main/java/com/example/g8backend/controller/UserController.java b/src/main/java/com/example/g8backend/controller/UserController.java
new file mode 100644
index 0000000..0bbcdc6
--- /dev/null
+++ b/src/main/java/com/example/g8backend/controller/UserController.java
@@ -0,0 +1,54 @@
+package com.example.g8backend.controller;
+
+import com.example.g8backend.entity.User;
+import com.example.g8backend.service.IUserService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@RestController
+@RequestMapping("/users")
+public class UserController {
+
+    @Autowired
+    private IUserService userService;
+
+    // 获取所有用户
+    @GetMapping
+    public List<User> getUsers() {
+        return userService.list();
+    }
+
+    // 通过ID获取用户
+    @GetMapping("/{id}")
+    public User getUserById(@PathVariable Long id) {
+        return userService.getById(id);
+    }
+
+    // 通过用户名获取用户
+    @GetMapping("/name/{name}")
+    public User getUserByName(@PathVariable String name) {
+        return userService.getUserByName(name);
+    }
+
+    // 添加用户
+    @PostMapping
+    public boolean addUser(@RequestBody User user) {
+        System.out.println(user);
+        return userService.save(user);
+    }
+
+    // 修改用户
+    @PutMapping
+    public boolean updateUser(@RequestBody User user) {
+        return userService.updateById(user);
+    }
+
+    // 删除用户
+    @DeleteMapping("/{id}")
+    public boolean deleteUser(@PathVariable Long id) {
+        return userService.removeById(id);
+    }
+}
+