初始化项目
This commit is contained in:
@@ -1,39 +1,19 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import UserManagement from './components/UserManagement.vue'
|
import LotteryResults from './components/LotteryResults.vue'
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="app">
|
<div class="app">
|
||||||
<header class="app-header">
|
<LotteryResults />
|
||||||
<h1>博彩管理系统</h1>
|
|
||||||
</header>
|
|
||||||
<main class="app-main">
|
|
||||||
<UserManagement />
|
|
||||||
</main>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.app {
|
.app {
|
||||||
max-width: 1200px;
|
width: 100%;
|
||||||
margin: 0 auto;
|
height: 100vh;
|
||||||
padding: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.app-header {
|
|
||||||
text-align: center;
|
|
||||||
margin-bottom: 30px;
|
|
||||||
padding-bottom: 20px;
|
|
||||||
border-bottom: 1px solid #e0e0e0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.app-header h1 {
|
|
||||||
color: #333;
|
|
||||||
font-size: 2.5rem;
|
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
padding: 0;
|
||||||
|
overflow: hidden;
|
||||||
.app-main {
|
|
||||||
min-height: 500px;
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,63 +0,0 @@
|
|||||||
package com.example.bocai.controller;
|
|
||||||
|
|
||||||
import com.example.bocai.entity.User;
|
|
||||||
import com.example.bocai.repository.UserRepository;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/api/users")
|
|
||||||
public class UserController {
|
|
||||||
@Autowired
|
|
||||||
private UserRepository userRepository;
|
|
||||||
|
|
||||||
// 获取所有用户
|
|
||||||
@GetMapping
|
|
||||||
public List<User> getAllUsers() {
|
|
||||||
return userRepository.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 根据ID获取用户
|
|
||||||
@GetMapping("/{id}")
|
|
||||||
public ResponseEntity<User> getUserById(@PathVariable Long id) {
|
|
||||||
Optional<User> user = userRepository.findById(id);
|
|
||||||
return user.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build());
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建新用户
|
|
||||||
@PostMapping
|
|
||||||
public User createUser(@RequestBody User user) {
|
|
||||||
return userRepository.save(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 更新用户
|
|
||||||
@PutMapping("/{id}")
|
|
||||||
public ResponseEntity<User> updateUser(@PathVariable Long id, @RequestBody User userDetails) {
|
|
||||||
Optional<User> user = userRepository.findById(id);
|
|
||||||
if (user.isPresent()) {
|
|
||||||
User updatedUser = user.get();
|
|
||||||
updatedUser.setName(userDetails.getName());
|
|
||||||
updatedUser.setEmail(userDetails.getEmail());
|
|
||||||
updatedUser.setPassword(userDetails.getPassword());
|
|
||||||
return ResponseEntity.ok(userRepository.save(updatedUser));
|
|
||||||
} else {
|
|
||||||
return ResponseEntity.notFound().build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 删除用户
|
|
||||||
@DeleteMapping("/{id}")
|
|
||||||
public ResponseEntity<Void> deleteUser(@PathVariable Long id) {
|
|
||||||
Optional<User> user = userRepository.findById(id);
|
|
||||||
if (user.isPresent()) {
|
|
||||||
userRepository.delete(user.get());
|
|
||||||
return ResponseEntity.noContent().build();
|
|
||||||
} else {
|
|
||||||
return ResponseEntity.notFound().build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package com.example.bocai.entity;
|
|
||||||
|
|
||||||
import jakarta.persistence.Entity;
|
|
||||||
import jakarta.persistence.GeneratedValue;
|
|
||||||
import jakarta.persistence.GenerationType;
|
|
||||||
import jakarta.persistence.Id;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
@Data
|
|
||||||
public class User {
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
private Long id;
|
|
||||||
private String name;
|
|
||||||
private String email;
|
|
||||||
private String password;
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
package com.example.bocai.repository;
|
|
||||||
|
|
||||||
import com.example.bocai.entity.User;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
|
|
||||||
public interface UserRepository extends JpaRepository<User, Long> {
|
|
||||||
User findByEmail(String email);
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user