Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
myspringweb
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
황 재인
myspringweb
Commits
ad4b9d53
Commit
ad4b9d53
authored
2 months ago
by
kim daeun
Browse files
Options
Downloads
Patches
Plain Diff
musicSearch
parent
2a475e33
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/com/ajou/procoding/myweb/controller/MyWebController.java
+51
-0
51 additions, 0 deletions
.../com/ajou/procoding/myweb/controller/MyWebController.java
src/main/java/com/ajou/procoding/myweb/dto/MusicList.java
+15
-0
15 additions, 0 deletions
src/main/java/com/ajou/procoding/myweb/dto/MusicList.java
with
66 additions
and
0 deletions
src/main/java/com/ajou/procoding/myweb/controller/MyWebController.java
0 → 100644
+
51
−
0
View file @
ad4b9d53
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
This diff is collapsed.
Click to expand it.
src/main/java/com/ajou/procoding/myweb/dto/MusicList.java
0 → 100644
+
15
−
0
View file @
ad4b9d53
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
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment