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
Admin message
During summer vacation, Gitlab will be restart frequently. Use it carefully.
Show more breadcrumbs
SangJun Park
My_Spring_Web
Commits
849ecf78
Commit
849ecf78
authored
Jul 17, 2023
by
SangJun Park
Browse files
Options
Downloads
Patches
Plain Diff
musicSearch
parent
82f1b46a
No related branches found
No related tags found
No related merge requests found
Pipeline
#8219
canceled
Jul 17, 2023
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
+48
-0
48 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
65 additions
and
0 deletions
src/main/java/kr/ajousw/myspringweb/controller/MyWebController.java
0 → 100644
+
48
−
0
View file @
849ecf78
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
{
@GetMapping
(
value
=
"/musicSearch/{term}"
)
public
MusicList
musicSearchByPath
(
@PathVariable
String
term
)
{
try
{
RestTemplate
restTemplate
=
new
RestTemplate
();
String
url
=
"https://itunes.apple.com/search?term="
+
term
+
"&entity=album"
;
String
response
=
restTemplate
.
getForObject
(
url
,
String
.
class
);
// String class로 변환
ObjectMapper
mapper
=
new
ObjectMapper
();
MusicList
list
=
mapper
.
readValue
(
response
,
MusicList
.
class
);
// MusicList 방식으로 변환
System
.
out
.
println
(
list
.
getResultCount
());
return
list
;
// MusicList를 반환
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
toString
());
return
null
;
}
}
@GetMapping
(
value
=
"/musicSearch"
)
public
MusicList
musicSearchByParam
(
@RequestParam
String
term
){
try
{
RestTemplate
restTemplate
=
new
RestTemplate
();
String
url
=
"https://itunes.apple.com/search?term="
+
term
+
"&entity=album"
;
String
response
=
restTemplate
.
getForObject
(
url
,
String
.
class
);
// String class로 변환
ObjectMapper
mapper
=
new
ObjectMapper
();
MusicList
list
=
mapper
.
readValue
(
response
,
MusicList
.
class
);
// MusicList 방식으로 변환
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 @
849ecf78
package
kr.ajousw.myspringweb.dto
;
import
java.util.List
;
import
java.util.Map
;
import
lombok.Getter
;
import
lombok.Setter
;
import
lombok.ToString
;
@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