Search code examples
springdto

Using Dto vs Primitive when there's only one parameter


If there's only one parameter from the request (for example, memberId received for deleting), should I bind that parameter to Dto or just use it as a primitive?

@DeleteMapping("/members/{memberId}")
ResponseEntity<String> deleteAccount(@PathVariable int memberId){
    memberService.deleteAccount(memberId);
    return ResponseEntity.status(HttpStatus.OK).body("");
}

VS

@DeleteMapping("/members/{memberId}")
ResponseEntity<String> deleteAccount(MemberDeleteDto member){
    memberService.deleteAccount(member);
    return ResponseEntity.status(HttpStatus.OK).body("");
}

Solution

  • I would say there is no rule for this, but my suggestion would be to keep it simple and use primitives whenever possible for path parameters. Unless you really have a very good reason for using a fully-fledged Object, I would suggest you not to over-engineer it.