Skip to content
Snippets Groups Projects
Select Git revision
  • 43b0d9bef233e11ccbed00da7a2c23242e29f2c2
  • main default protected
2 results

MyWebController.java

Blame
  • MyWebController.java 1.32 KiB
    package com.ajou.prcoding.myweb.Controller;
    
    import org.codehaus.jackson.map.ObjectMapper;
    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 java.io.IOException;
    import java.net.URI;
    
    import com.ajou.prcoding.myweb.dto.MusicList;
    
    @RestController
    public class MyWebController {
    
        RestTemplate restTemplate = new RestTemplate();
        MusicList list;
    
        @GetMapping(value = "/musicSearch/{term}")
        public MusicList musicSearchByPath(@PathVariable String term){
            try {
                String url = "https://itunes.apple.com/search?term=aespa&entity=album";
                String response = restTemplate.getForObject(url, String.class);
                ObjectMapper mapper = new ObjectMapper();
    
                list = mapper.readValue(response, MusicList.class);
                System.out.println(list.getResultCount());
                return list;
            }catch (IOException e){
                System.out.println(e.toString());
            }
            return list;
        }
        @GetMapping(value = "/musicSearch")
        public String musicSearchByParam(@RequestParam String term){
            return "Hello Param!";
        }
    }