일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- java
- 김영한
- springdatajpa
- Spring Boot
- jpa
- Servlet
- Exception
- Greedy
- QueryDSL
- 백준
- pointcut
- db
- JDBC
- 그리디
- Android
- Thymeleaf
- http
- Proxy
- kotlin
- 스프링 핵심 원리
- 자바
- JPQL
- 인프런
- 알고리즘
- 스프링 핵심 기능
- 스프링
- SpringBoot
- AOP
- transaction
- spring
- Today
- Total
목록json (9)
개발자되기 프로젝트
이번에 Json을 많이 다루면서 가장 큰 문제점은 양이 많아서 한눈에 보기 어려웠다. viewer를 찾는 도중 요게 그나마 사용하기 편하고 포기 편함. Online JSON Viewer jsonviewer.stack.hu 사진처럼 트리 형태이기 때문에, 양이 많아도 필요한 부분만 확인할 수 있음, 검색도 가능.
Retrofit사용 시 요청이 계속 fail이 나서 검색하던 중 Json to Kotlin class 라는 plugin을 알게되었다. 응답 받을 또는 응답을 줄 json samle을 입력하면 이에 맞춰 클래스를 생성하는 기능을 제공한다... setting -> plugin에서 json이라고 검색하면 가장 먼저 확인할 수 있다. 설치가 되었다면 클래스 생성 시 아래와 같이 확인이 가능하다. 생성할 때 이제 josn sample을 넣어주면 클래스를 생성해준다. 일부러 복잡한 sample을 사용했다. 생성 결과
1. 도시내 길찾기 출력 데이터 번호 요소 데이터 타입 필수값 출력 개수 설명 1 result 확장노드 Y 1 데이터를 포함하는 최 상위 노드 1-1 searchType int Y 1 결과 구분 (도시내 or 도시간 직통 or 도시간 환승) 0-도시내, 1-도시간 직통, 2-도시간 환승 1-2 outTrafficCheck int Y 1 도시간 "직통" 탐색 결과 유무(환승 X) 0-False, 1-True 1-3 busCount int Y 1 버스 결과 개수 1-4 subwayCount int Y 1 지하철 결과 개수 1-5 subwayBusCount int Y 1 “버스+지하철” 결과 개수 1-6 pointDistance double Y 1 출발지(SX, SY)와 도착지(EX, EY)의 직선 거리 (미..
API예외 처리는 SpringBoot의 기본 오류 처리 방식을 사용할 수 있음. 1. BasicErrorController SpringBoot가 제공하는 기본 ErrorController @Controller @RequestMapping("${server.error.path:${error.path:/error}}") public class BasicErrorController extends AbstractErrorController { @RequestMapping(produces = MediaType.TEXT_HTML_VALUE) public ModelAndView errorHtml(HttpServletRequest request, HttpServletResponse response) {} @Reques..
HTML 페이지의 경우 지금까지 설명했던 것 처럼 4xx, 5xx와 같은 오류 페이지만 있으면 대부분의 문제를 해결할 수 있음. API는 각 오류 상황에 맞는 오류 응답 스펙을 정하고, JSON으로 데이터를 내려줘야함. 1. WevServerCustomizer WAS에 예외가 전달되거나, response.sendError() 가 호출되면 위에 등록한 예외 페이지 경로가 호출됨. import org.springframework.boot.web.server.ConfigurableWebServerFactory; import org.springframework.boot.web.server.ErrorPage; import org.springframework.boot.web.server.WebServerFactor..
1. JSON 형식 data 받기 v1 ObjectMapper : JSON Object @Slf4j @Controller public class RequestBodyJsonController { private ObjectMapper objectMapper = new ObjectMapper(); @PostMapping("/request-body-json-v1") public void requestBodyJsonV1(HttpServletRequest request, HttpServletResponse response) throws IOException { ServletInputStream inputStream = request.getInputStream(); String messageBody = Stream..
1. MessageBody에 JSON을 담아서 보내보자! objectMapper.writeValueAsString()을 통해 Object -> JSON 변환 response.getWriter().write() 를 통해 body에 담음. @WebServlet(name = "ResponseJsonServlet", urlPatterns = "/response-json") public class ResponseJsonServlet extends HttpServlet { ObjectMapper objectMapper = new ObjectMapper(); @Override protected void service(HttpServletRequest request, HttpServletResponse response..
1. HTTP 요청 데이터 - API 메시지 바디 - JSON HTTP API에서 주로 사용하는 JSON 형식으로 데이터를 전달해보자. 2. JSON형식 전송 POST http://localhost:8080/request-body-json content-type: application/json message body: {"username": "hello", "age": 20} 결과: messageBody = {"username": "hello", "age": 20} 3. JSON형식 파싱 추가 JSON형식으로 파싱할 객체를 생성 @Getter @Setter public class HelloData { private String username; private int age; } 4. JSON 받기. @W..