2. JSON
저번 시간에 이어 DB의 내용들을 JSON Type을 return 하도록 하겠습니다.
- test_table
- test_table_column
- RestController.java
controller에 api 정보를 등록합니다.
ResponseEntity를 이용하여 tableMetadats 의 List Type을 가져오도록 합니다.
// Table Meta 정보를 조회
@GetMapping("/tables/metadata")
public ResponseEntity<List<TestTable>> readTableMetadatas() {
List<TestTable> tableMetadatas = restService.getTableMetadatas();
return ResponseEntity.ok(tableMetadatas);
}
- RestService.java
간단하게 전체 데이터를 조회하여 return 합니다.
public List<TestTable> getTableMetadatas() {
List<TestTable> testTables = testTableRepository.findAll();
return testTables;
}
- REST API 호출
- Response
[
{
"id": 1,
"name": "test_table_1",
"columns": [
{
"id": 1,
"columnName": "table_column_1_1",
"columnDataType": "string"
},
{
"id": 2,
"columnName": "table_column_1_2",
"columnDataType": "long"
},
{
"id": 3,
"columnName": "table_column_1_3",
"columnDataType": "timestamp"
}
]
},
{
"id": 2,
"name": "test_table_2",
"columns": [
{
"id": 4,
"columnName": "table_column_2_1",
"columnDataType": "string"
},
{
"id": 5,
"columnName": "table_column_2_2",
"columnDataType": "long"
},
{
"id": 6,
"columnName": "table_column_2_3",
"columnDataType": "timestamp"
}
]
}
]
테이블명과 테이블 컬럼 정보가 정상적으로 잘 나오는 것을 확인하였습니다. :)
'Apache Avro' 카테고리의 다른 글
Rest-API 구현 관련 과제 - 3 (예외처리) (0) | 2024.11.03 |
---|---|
Rest-API 구현 관련 과제 - 1 (Avro) (0) | 2024.10.27 |
Rest-API 구현 관련 과제 (0) | 2024.10.09 |
Spring Boot REST API 및 DB 연동 실습 - 3 (DBtoAvro) (0) | 2024.09.29 |
Spring Boot REST API 및 DB 연동 실습 - 2 (JPA) (0) | 2024.09.28 |
댓글