Spring Rest Controller @PostMapping parameter best practice ?
資深大佬 : AkideLiu 8
一般 postmapping 接收 json 数据的时候用什么格式比较好呢? DTO object 还是 map ?
以下两个例子对比一下你觉得哪个好呢?
- Map:
@PostMapping("") public ResponseEntity<Transaction> addTransaction(HttpServletRequest request, @PathVariable("categoryId") Integer categoryId, @RequestBody Map<String, Object> transactionMap) {
https://github.com/pairlearning/expense-tracker-api/blob/5cb647f06797f2da554e04d89943b1bfb4fe1e00/src/main/java/com/pairlearning/expensetracker/resources/TransactionResource.java#L39-L42
- DTO object:
@PostMapping(path = "/", consumes = "application/json", produces = "application/json") public ApiResultBean createOrUpdatePeople(@Valid @RequestBody PostPeopleDTO postPeopleDTO) throws JsonProcessingException {
大佬有話說 (12)