API 서버를 개발할 때 Request를 받아올 DTO를 생성해서 사용
@Getter
@Setter
@Entity
public class Member {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private String phone;
``` java
@PostMapping("/members/new")
@ResponseBody
public String create(@RequestBody String name, @RequestBody String phone) {
memberService.join(member);
return "등록성공";
}
@PostMapping("/members/new")
@ResponseBody
public String create(@RequestBody @Valid Member member) {
memberService.join(member);
return "등록성공";
}
@Getter
public class AddMemberDto {
private String name;
private String phone;
}
@Getter
public class UpdateNameMemberDto {
private String name;
}
@Getter
public class UpdatePhoneMemberDto {
private String phone;
}
@PostMapping("/members/new")
@ResponseBody
public String create(@RequestBody @Valid AddMemberDto dto) {
memberService.join(dto);
return "등록성공";
}
@Getter
@AllArgsConstructor
public class MenberDto {
@Getter
@AllArgsConstructor
@NoArgsConstructor
public static class Res {
private Long id;
private String name;
private String phone;
}
@Getter
@AllArgsConstructor
@NoArgsConstructor
public static class Add {
private String name;
private String phone;
}
@Getter
@AllArgsConstructor
@NoArgsConstructor
public static class UpdateName {
private String name;
}
@Getter
@AllArgsConstructor
@NoArgsConstructor
public static class UpdatePhone {
private String phone;
}
}