Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
B
bookinfo-pageproduct
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
禅道
禅道
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
黄兴尧
bookinfo-pageproduct
Commits
470d0e21
提交
470d0e21
authored
3月 08, 2021
作者:
huangxingyao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
.
上级
ed587c8d
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
15 行增加
和
3 行删除
+15
-3
ProductPageController.java
src/main/java/com/bookinfo/rest/ProductPageController.java
+15
-3
没有找到文件。
src/main/java/com/bookinfo/rest/ProductPageController.java
浏览文件 @
470d0e21
...
@@ -3,10 +3,12 @@ package com.bookinfo.rest;
...
@@ -3,10 +3,12 @@ package com.bookinfo.rest;
import
com.bookinfo.client.DetailsClient
;
import
com.bookinfo.client.DetailsClient
;
import
com.bookinfo.client.ReviewsClient
;
import
com.bookinfo.client.ReviewsClient
;
import
com.bookinfo.entity.Product
;
import
com.bookinfo.entity.Product
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.MediaType
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.ui.Model
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.client.HttpClientErrorException
;
import
org.springframework.web.client.HttpClientErrorException
;
import
org.springframework.web.client.RestClientException
;
import
org.springframework.web.client.RestClientException
;
...
@@ -15,8 +17,10 @@ import javax.servlet.http.HttpServletRequest;
...
@@ -15,8 +17,10 @@ import javax.servlet.http.HttpServletRequest;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Objects
;
@Controller
@Controller
@Slf4j
public
class
ProductPageController
{
public
class
ProductPageController
{
@Autowired
@Autowired
private
DetailsClient
detailsClient
;
private
DetailsClient
detailsClient
;
...
@@ -58,6 +62,8 @@ public class ProductPageController {
...
@@ -58,6 +62,8 @@ public class ProductPageController {
response
.
setHeader
(
"end-user"
,
user
);
response
.
setHeader
(
"end-user"
,
user
);
return
"productpage"
;
return
"productpage"
;
}
}
...
@@ -82,10 +88,13 @@ public class ProductPageController {
...
@@ -82,10 +88,13 @@ public class ProductPageController {
private
void
getDetails
(
int
idProduct
,
Model
model
)
{
private
void
getDetails
(
int
idProduct
,
Model
model
)
{
try
{
try
{
model
.
addAttribute
(
"details"
,
detailsClient
.
getDetail
(
idProduct
));
Object
detail
=
detailsClient
.
getDetail
(
idProduct
);
log
.
info
(
"[bowen-bookinfo-app]-[productpage/getDetails], resp={}"
,
Objects
.
isNull
(
detail
)
?
"detail is empty"
:
detail
.
toString
());
model
.
addAttribute
(
"details"
,
detail
);
model
.
addAttribute
(
"detailsStatus"
,
200
);
model
.
addAttribute
(
"detailsStatus"
,
200
);
}
}
catch
(
RestClientException
ex
){
catch
(
RestClientException
ex
){
log
.
error
(
"[bowen-bookinfo-app]-[productpage/getDetails], exception={}"
,
ex
.
getMessage
());
if
(
ex
instanceof
HttpClientErrorException
){
if
(
ex
instanceof
HttpClientErrorException
){
model
.
addAttribute
(
"detailsStatus"
,
((
HttpClientErrorException
)
ex
).
getStatusCode
());
model
.
addAttribute
(
"detailsStatus"
,
((
HttpClientErrorException
)
ex
).
getStatusCode
());
}
}
...
@@ -100,12 +109,15 @@ public class ProductPageController {
...
@@ -100,12 +109,15 @@ public class ProductPageController {
String
user
=
(
request
.
getSession
()
==
null
)?
""
:
(
String
)
request
.
getSession
().
getAttribute
(
"user"
);
String
user
=
(
request
.
getSession
()
==
null
)?
""
:
(
String
)
request
.
getSession
().
getAttribute
(
"user"
);
model
.
addAttribute
(
"reviews"
,
reviewsClient
.
getReviews
(
idProduct
,
user
));
List
<
Object
>
reviews
=
reviewsClient
.
getReviews
(
idProduct
,
user
);
model
.
addAttribute
(
"reviews"
,
reviews
);
log
.
info
(
"[bowen-bookinfo-app]-[productpage/getReviews], resp={}"
,
CollectionUtils
.
isEmpty
(
reviews
)
?
"reviews is empty"
:
reviews
.
toString
());
model
.
addAttribute
(
"reviewsStatus"
,
200
);
model
.
addAttribute
(
"reviewsStatus"
,
200
);
}
}
catch
(
RestClientException
ex
){
catch
(
RestClientException
ex
){
System
.
out
.
println
(
ex
);
log
.
error
(
"[bowen-bookinfo-app]-[productpage/getReviews], exception={}"
,
ex
.
getMessage
()
);
if
(
ex
instanceof
HttpClientErrorException
){
if
(
ex
instanceof
HttpClientErrorException
){
model
.
addAttribute
(
"reviewsStatus"
,
((
HttpClientErrorException
)
ex
).
getStatusCode
());
model
.
addAttribute
(
"reviewsStatus"
,
((
HttpClientErrorException
)
ex
).
getStatusCode
());
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论