mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Merge pull request #30027 from wonwoo
* gh-30027: Polish RestController examples Closes gh-30027
This commit is contained in:
commit
ef927627de
@ -37,17 +37,17 @@ public class MyRestController {
|
||||
this.customerRepository = customerRepository;
|
||||
}
|
||||
|
||||
@GetMapping("/{user}")
|
||||
@GetMapping("/{userId}")
|
||||
public User getUser(@PathVariable Long userId) {
|
||||
return this.userRepository.findById(userId).get();
|
||||
}
|
||||
|
||||
@GetMapping("/{user}/customers")
|
||||
@GetMapping("/{userId}/customers")
|
||||
public List<Customer> getUserCustomers(@PathVariable Long userId) {
|
||||
return this.userRepository.findById(userId).map(this.customerRepository::findByUser).get();
|
||||
}
|
||||
|
||||
@DeleteMapping("/{user}")
|
||||
@DeleteMapping("/{userId}")
|
||||
public void deleteUser(@PathVariable Long userId) {
|
||||
this.userRepository.deleteById(userId);
|
||||
}
|
||||
|
@ -38,19 +38,19 @@ public class MyRestController {
|
||||
this.customerRepository = customerRepository;
|
||||
}
|
||||
|
||||
@GetMapping("/{user}")
|
||||
@GetMapping("/{userId}")
|
||||
public Mono<User> getUser(@PathVariable Long userId) {
|
||||
return this.userRepository.findById(userId);
|
||||
}
|
||||
|
||||
@GetMapping("/{user}/customers")
|
||||
@GetMapping("/{userId}/customers")
|
||||
public Flux<Customer> getUserCustomers(@PathVariable Long userId) {
|
||||
return this.userRepository.findById(userId).flatMapMany(this.customerRepository::findByUser);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{user}")
|
||||
public void deleteUser(@PathVariable Long userId) {
|
||||
this.userRepository.deleteById(userId);
|
||||
@DeleteMapping("/{userId}")
|
||||
public Mono<Void> deleteUser(@PathVariable Long userId) {
|
||||
return this.userRepository.deleteById(userId);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user