first commit
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package com.yundage.chat.controller;
|
||||
|
||||
import com.yundage.chat.entity.User;
|
||||
import com.yundage.chat.mapper.UserMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/users")
|
||||
public class UserController {
|
||||
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
|
||||
@GetMapping
|
||||
public List<User> getAllUsers() {
|
||||
return userMapper.selectAll();
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public User getUserById(@PathVariable Long id) {
|
||||
return userMapper.selectOneById(id);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public User createUser(@RequestBody User user) {
|
||||
user.setCreateTime(LocalDateTime.now());
|
||||
user.setUpdateTime(LocalDateTime.now());
|
||||
userMapper.insert(user);
|
||||
return user;
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public User updateUser(@PathVariable Long id, @RequestBody User user) {
|
||||
user.setId(id);
|
||||
user.setUpdateTime(LocalDateTime.now());
|
||||
userMapper.update(user);
|
||||
return user;
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public void deleteUser(@PathVariable Long id) {
|
||||
userMapper.deleteById(id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user