본문 바로가기
프로그래밍

[공공데이터포탈] 데이터 활용 air korea

by 개발자신입 2024. 3. 12.
반응형

공공데이터포탈 (Air Korea)

menu.html

      <li class="nav-item"><a class="nav-link me-lg-3" href="/airKorea">Air Korea</a></li>

에어코리아 상세정보

 

 

 

package com.example.web.controller;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class APIController {
	
	@GetMapping("/airKorea")
	public String airKorea(Model model) throws IOException {
		StringBuilder urlBuilder = new StringBuilder("http://apis.data.go.kr/B552584/ArpltnInforInqireSvc/getMinuDustFrcstDspth");
		urlBuilder.append("?serviceKey=   ");
		urlBuilder.append("&returnType=xml");
		urlBuilder.append("&numOfRow=100");
		urlBuilder.append("&pageNo=1");
		urlBuilder.append("&searchDate=2024-03-11");
		urlBuilder.append("&informCode=PM10");
		
		URL url = new URL(urlBuilder.toString());
		HttpURLConnection conn = (HttpURLConnection) url.openConnection();
		conn.setRequestMethod("GET");
		conn.setRequestProperty("Content-type", "application/json");
		System.out.println("Response code : " + conn.getResponseCode()); // Response code : 200
		
		return "airKorea";
	}
}

 

결과 출력창

Response code : 200

반응형

댓글