Skip to content
Snippets Groups Projects
Commit ad4b9d53 authored by kim daeun's avatar kim daeun
Browse files

musicSearch

parent 2a475e33
Branches patch-1
No related tags found
No related merge requests found
package com.ajou.procoding.myweb.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.ajou.procoding.myweb.dto.MusicList;
import com.fasterxml.jackson.databind.ObjectMapper;
@RestController
public class MyWebController {
@GetMapping(value="/musicSearch/{term}")
public MusicList musicSearchByPath(@PathVariable String term) {
try {
String url = String.format("https://itunes.apple.com/search?term=%s&entity=album", term);
String response = restTemplate.getForObject(url, String.class);
//String response = restTemplate.getForObject("https://itunes.apple.com/search?term=aespa&entity=album", String.class);
ObjectMapper mapper = new ObjectMapper();
MusicList list = mapper.readValue(response, MusicList.class);
System.out.println(list.getResultCount());
return list;
} catch(IOException e) {
System.out.println(e.toString());
}
return null;
}
@GetMapping(value="/musicSearch")
public MusicList musicSearchByParam(@RequestParam String term){
try {
String url = String.format("https://itunes.apple.com/search?term=%s&entity=album", term);
String response = restTemplate.getForObject(url, String.class);
//String response = restTemplate.getForObject("https://itunes.apple.com/search?term=aespa&entity=album", String.class);
ObjectMapper mapper = new ObjectMapper();
MusicList list = mapper.readValue(response, MusicList.class);
System.out.println(list.getResultCount());
return list;
} catch(IOException e) {
System.out.println(e.toString());
}
return null;
}
//몇 줄 아닌거 같아 보이는데 많은 일을 함
RestTemplate restTemplate = new RestTemplate();
}
\ No newline at end of file
package com.ajou.procoding.myweb.dto;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.util.List;
import java.util.Map;
@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