提交 470d0e21 authored 作者: huangxingyao's avatar huangxingyao

.

上级 ed587c8d
...@@ -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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论