Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
My Spring Web
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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
한이지
My Spring Web
Commits
a238d09d
Commit
a238d09d
authored
2 years ago
by
한이지
Browse files
Options
Downloads
Patches
Plain Diff
musicSearch
parent
ee5d189a
No related branches found
No related tags found
No related merge requests found
Pipeline
#8241
canceled
2 years ago
Stage: build
Stage: test
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/kr/ajousw/myspringweb/controller/MyWebController.java
+65
-0
65 additions, 0 deletions
...ava/kr/ajousw/myspringweb/controller/MyWebController.java
src/main/java/kr/ajousw/myspringweb/dto/MusicList.java
+17
-0
17 additions, 0 deletions
src/main/java/kr/ajousw/myspringweb/dto/MusicList.java
with
82 additions
and
0 deletions
src/main/java/kr/ajousw/myspringweb/controller/MyWebController.java
0 → 100644
+
65
−
0
View file @
a238d09d
package
kr.ajousw.myspringweb.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.fasterxml.jackson.databind.ObjectMapper
;
import
kr.ajousw.myspringweb.dto.MusicList
;
@RestController
public
class
MyWebController
{
RestTemplate
restTemplate
=
new
RestTemplate
();
@GetMapping
(
value
=
"/musicSearch/{term}"
)
public
MusicList
musicSearchByPath
(
@PathVariable
String
term
)
{
String
url
=
"https://itunes.apple.com/search?term="
+
term
+
"&entity=album"
;
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
;
}
}
@GetMapping
(
value
=
"/musicSearch"
)
public
MusicList
musicSearchByParam
(
@RequestParam
String
term
){
String
url
=
"https://itunes.apple.com/search?term="
+
term
+
"&entity=album"
;
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
;
}
}
}
This diff is collapsed.
Click to expand it.
src/main/java/kr/ajousw/myspringweb/dto/MusicList.java
0 → 100644
+
17
−
0
View file @
a238d09d
package
kr.ajousw.myspringweb.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