์ ์ ๋ง๋ค์๋ VIP ์ด๋์ฅ ํ๋ก์ ํธ ์ค
๊ณ ๊ฐ ๊ด๋ จ ๋ถ๋ถ์์ DTO ์์ด ์์ฑํ์๋ค.
Codex์๊ฒ DTO๋ฅผ ์ถ๊ฐํด๋ณด๋๋ก ํ๊ฒ ๋ค.
1. Codex App
- ํ๋ก์ ํธ ์ถ๊ฐํ๊ธฐ

๊ธฐ์กด ํ๋ก์ ํธ๋ฅผ ์์ ํ๊ณ ์ถ๋ค๋ฉด ๊ธฐ์กด ํด๋ ์ฌ์ฉํด์ ๋ฃ์ด์ฃผ๋ฉด ๋๋ค.
- ํ๋ก์ ํธ ๊ตฌ์กฐ ํ์ ์ํค๊ธฐ

์ ํํ ๋ต๋ณ์ ๋ฐ๊ธฐ ์ํด ์ฝ๋ฑ์ค์๊ฒ ์์ ๊ฐ์ ๋ช ๋ น์ ํ๋ค. ์ด๋ ๊ฒ ๊ตฌ์กฐ ํ์ ์ ์ํค๋ ์ง๋ฌธ์ ๋จผ์ ํ๋ฉด ๋ค๋ฅธ ๋์์ ์ํํ์๋ ์ ํ๋๋ฅผ ๋์ผ ์ ์๋ค๊ณ ํ๋ค!
- ์ํ๋ ๋ชฉํ๋ฅผ ์ ํํ๊ฒ ๋งํ๊ธฐ

์บก์ณ๋ณธ์๋ ์๋์์ง๋ง ์์ ๊ณ ๊ฐ๊ด๋ฆฌDTO์ ๋ํด ์ญ ์ด์ผ๊ธฐ๋ฅผ ํ๊ณ , ๊ทธ ๋ค์์ DTO๋ฅผ ์ถ๊ฐํด๋ฌ๋ผ๊ณ ํ์ต๋๋ค. ์ฌ์ค ๋ ์ ํํ ๋ต๋ณ์ ์ป์ผ๋ ค๋ฉด [ DTO๋ฅผ ์ถ๊ฐํด์ฃผ๊ณ ๊ทธ์ ๋ง๊ฒ Controller์ Service ํด๋์ค๋ ์์ ํด์ค. ]๋ผ๊ณ ํ๋ฉด ๋๋ค๋ค์. ๋ณต์กํ ํ๋ก์ ํธ์ ๊ฒฝ์ฐ๋ ์ด๋ ์ปดํฌ๋ํธ ํน์ ๋ฉ์๋๋ฅผ ์์ ํด๋ฌ๋ผ๊ณ ์์ฑํ๋ฉด ํจ์ฌ ๋ ์ข์ ์ฝ๋๋ฅผ ์ป๋๋ค๊ณ ๋ค์์ต๋๋ค. ๋ค๋ง ์ ํ๋ก์ ํธ๋ ๊ตฌ์กฐ๊ฐ ๊ฐ๋จํ ํธ์ด๋ผ์ ๋์ถฉ ์ง๋ฌธํด๋ ^_^ ๋๋ํ ์ฝ๋ฑ์ค๊ฐ! ์ ์์๋ค์๊ฑฐ๋ผ ๋ฏฟ์์ต๋๋ค.
2. ์์
- ์์ ์ /ํ


- CustomerRequset
@Getter
@Setter
public class CustomerRequest {
private String name;
private String grade;
private String phone;
private String code;
private String note;
}
- CustomerResponse
@Getter
@Setter
public class CustomerResponse {
private Long id;
private String name;
private String grade;
private String phone;
private String code;
private String note;
}
- CustomerController
- ์์ ์
@GetMapping
public List<Customer> effectCustomers() {
return customerService.findAllCustomers();
}
@PostMapping
public Customer saveCustomer(@RequestBody Customer customer) {
return customerService.save(customer);
}
@PutMapping("/{id}")
public ResponseEntity<Customer> updateCustomer(
@PathVariable Long id,
@RequestBody Customer data
) {
Customer updated = customerService.update(id, data);
return ResponseEntity.ok(updated);
}
์ฝ๋๋ฅผ ๋ณด๋ฉด ์์ ์ ์๋ Entity์ Customer๋ฅผ ๊ทธ๋๋ก ๊ฐ์ ธ์์ ์ฌ์ฉํ๋ค.
- ์์ ํ
@GetMapping
public List<CustomerResponse> effectCustomers() {
return customerService.findAllCustomers();
}
@PostMapping
public CustomerResponse saveCustomer(@RequestBody CustomerRequest request) {
return customerService.save(request);
}
@PutMapping("/{id}")
public ResponseEntity<CustomerResponse> updateCustomer(
@PathVariable Long id,
@RequestBody CustomerRequest request
) {
CustomerResponse updated = customerService.update(id, request);
return ResponseEntity.ok(updated);
}
DTO๋ฅผ ๋ง๋ ํ Codex๋ ์์์ Controller ์ฝ๋๊น์ง ์์ฒญ๊ณผ ์๋ต์ DTO๋ก ๋ฐ๊ฟจ๋ค.
- CustomerService
- ์์ ์ (์กฐํ๋ถ๋ถ)
public List<Customer> findAllCustomers() {
return customerRepository.findAll();
}
DB์์ ๊ฐ์ ธ์จ Customer ์ํฐํฐ ๋ชฉ๋ก์ ๊ทธ๋๋ก ๋ฐํํ๋ค.
- ์์ ํ (์กฐํ๋ถ๋ถ)
public List<CustomerResponse> findAllCustomers() {
return customerRepository.findAll().stream()
.map(this::toResponse)
.toList();
}
DB์์ ๊ฐ์ ธ์จ Entity ๋ฆฌ์คํธ๋ฅผ stream์ ์จ์ DTO๋ก ํ๋์ฉ ๋ณํํ๋ค. ๊ทธ๋ ๊ฒ ์๋ก์ด DTO ๋ฆฌ์คํธ๋ฅผ ์์ฑํ๋ค.
GPT ์ ๋ฃ๋ฅผ ์ด์ฉ ์ค์ด๋ผ๋ฉด Codex๋ฅผ ์ถ๊ฐ๊ธ ์์ด ์ด์ฉ ๊ฐ๋ฅํด์ ํ ๋ฒ ์ฌ์ฉํด๋ดค๋ค. ๊ฒฐ๋ก ์ ๋๋ฌด๋๋ฌด ํธํ๋ค. ์ฌ์ค ์ด๊ธฐ ์ธํ ์ด ์ด๋ ค์ธ๊น๋ด ์ข ๊ฑฑ์ ํ๋๋ฐ ๊ทธ๋ ์ง๋ ์๊ณ ๋๋ฌด ๊ฐ๋จํด์ ์์ฃผ ๊ตณ! ํด๋ก๋๋ ๋ค๋ฅธ AI ์์ด์ ํธ๋ฅผ ์ด์ฉํ์ง ์์๋ค๋ฉด ์ฝ๋ฑ์ค๋ผ๋ ๊ผญ ์ด์ฉํด๋ณด์๊ธธ!!! ๊ฐ์ถ๋๋ฆฝ๋๋ค.
'๐ค Codex' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| Codex๋ ๋ฌด์์ด๋ฉฐ ์ด๋ป๊ฒ ์ฌ์ฉํ๋ ๊ฒ์ธ๊ฐ? (0) | 2026.05.20 |
|---|