【发布时间】:2020-02-04 23:51:18
【问题描述】:
我有以下简单的Java
控制器和Spring Web
框架:
@RestController
@RequestMapping("/rounds")
@Slf4j
public class RoundController {
private RoundService roundService;
@Autowired
public RoundController(RoundService roundService) {
this.roundService = roundService;
}
@GetMapping(
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public List<Round> find() {
return roundService.find();
}
@GetMapping(
path = "/{userId}",
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public List<Round> get(@PathVariable String userId) {
return roundService.getRoundsByUserId(userId);
}
@PostMapping(
produces = MediaType.APPLICATION_JSON_VALUE
)
@ResponseStatus(HttpStatus.CREATED)
public Round create(@Valid @NotNull @RequestBody Round round) {
roundService.create(round);
return round;
}
@DeleteMapping(
path = "/{id}",
produces = MediaType.APPLICATION_JSON_VALUE
)
@ResponseStatus(HttpStatus.OK)
public void delete(@PathVariable String id) {
ObjectId objectId = new ObjectId(id);
roundService.delete(objectId);
}
}
在使用Mongo
时,是否有对对象进行更新/修补的最佳做法?
最好只使用POST
方法,并使用用户所做的更改将Round 对象重新保存在数据库中吗?
【问题讨论】:
标签: java spring mongodb rest patch