Skip to content
Snippets Groups Projects
Commit 849ecf78 authored by SangJun Park's avatar SangJun Park
Browse files

musicSearch

parent 82f1b46a
No related branches found
No related tags found
No related merge requests found
Pipeline #8219 canceled
package kr.ajousw.myspringweb.controller;
import java.io.IOException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import com.fasterxml.jackson.databind.ObjectMapper;
import kr.ajousw.myspringweb.dto.MusicList;
@RestController
public class MyWebController {
@GetMapping(value = "/musicSearch/{term}")
public MusicList musicSearchByPath(@PathVariable String term) {
try {
RestTemplate restTemplate = new RestTemplate();
String url = "https://itunes.apple.com/search?term=" + term + "&entity=album";
String response = restTemplate.getForObject(url, String.class); // String class로 변환
ObjectMapper mapper = new ObjectMapper();
MusicList list = mapper.readValue(response, MusicList.class); // MusicList 방식으로 변환
System.out.println(list.getResultCount());
return list; // MusicList를 반환
} catch (IOException e) {
System.out.println(e.toString());
return null;
}
}
@GetMapping(value = "/musicSearch")
public MusicList musicSearchByParam(@RequestParam String term){
try {
RestTemplate restTemplate = new RestTemplate();
String url = "https://itunes.apple.com/search?term=" + term + "&entity=album";
String response = restTemplate.getForObject(url, String.class); // String class로 변환
ObjectMapper mapper = new ObjectMapper();
MusicList list = mapper.readValue(response, MusicList.class); // MusicList 방식으로 변환
System.out.println(list.getResultCount());
return list;
} catch (IOException e) {
System.out.println(e.toString());
return null;
}
}
}
package kr.ajousw.myspringweb.dto;
import java.util.List;
import java.util.Map;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@ToString
public class MusicList {
private Integer resultCount;
private List<Map<String, Object>> results;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment