PageController.java 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package com.overseas.website.controller;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.overseas.website.utils.RequestUtil;
  4. import org.springframework.stereotype.Controller;
  5. import org.springframework.ui.Model;
  6. import org.springframework.web.bind.annotation.GetMapping;
  7. import org.springframework.web.bind.annotation.PathVariable;
  8. import java.util.HashMap;
  9. import java.util.Map;
  10. /**
  11. * Description
  12. *
  13. * @author : Charles
  14. * @date : 2021/10/18
  15. */
  16. @Controller
  17. public class PageController {
  18. /**
  19. * 页面路径
  20. */
  21. @GetMapping("/{path}.html")
  22. public String page(final Model model, @PathVariable("path") String path) {
  23. model.addAttribute("path", path);
  24. return path;
  25. }
  26. /**
  27. * 商品详情页面
  28. */
  29. @GetMapping("/product/{id}.html")
  30. public String product(final Model model, @PathVariable("id") String productId) {
  31. model.addAttribute("path", "product");
  32. Map<String, Object> product = new HashMap<>();
  33. try {
  34. String floorResult = RequestUtil.sendGet("https://core.caimei365.com/commodity/product/details?productId="+productId);
  35. Map<String, Object> floorMap = JSONObject.parseObject(floorResult, Map.class);
  36. product = JSONObject.parseObject(String.valueOf(floorMap.get("data")), Map.class);
  37. } catch (Exception e) {
  38. return null;
  39. }
  40. model.addAttribute("product", product);
  41. return "product";
  42. }
  43. }