Skip to content
Snippets Groups Projects
Commit f0ff2e22 authored by 장 무현's avatar 장 무현
Browse files

second

parent 880a722b
Branches
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 String musicSearchByPath(@PathVariable String term) {
return "";
}
@GetMapping(value="/musicSearch")
public MusicList musicSearchByParam(@RequestParam String term) { RestTemplate restTemplate = new RestTemplate();
String url = String.format("https://itunes.apple.com/search?term=%s&entity=album", term);
try {
String response = restTemplate.getForObject(url, 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;
}}
}
package com.ajou.procoding.myweb.dto;
import java.util.List;
import java.util.Map;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
@Tostring
public class MusicList {
private Integer resultCount;
private List<Map<String, Object>> results;
}
package com.ajou.procoding.myweb.dto;
public @interface Tostring {
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment