Skip to content
Snippets Groups Projects
Commit 56a26872 authored by 김준하's avatar 김준하
Browse files

musicSearch request code

parent e70cfe9a
Branches
No related tags found
1 merge request!2Master
package com.ajou.prcoding.myweb.Controller;
import com.ajou.prcoding.myweb.dto.MusicList;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import java.io.IOException;
@RestController
public class MyWebController {
RestTemplate restTemplate = new RestTemplate();
@GetMapping(value="/musicSearch/{term}")
public MusicList musicSearchByPath(@PathVariable String term){
try {
String url = "https://itunes.apple.com/search?term=" + term + "&entity=album";
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.prcoding.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;
}
This diff is collapsed.
<!doctype html>
<html>
<head>
<title> muiBasic </title>
<meta charset="UTF-8"/>
</head>
<body>
<div id="app"></div>
<script src="./bundle.js" type="text/javascript"></script>
</body>
</html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment