乐优商城(09)--商品详情

乐优商城(09)–商品详情

一、商品详情

1.1、商品详情页服务

商品详情浏览量比较大,并发高,所以独立开发一个微服务,用来展示商品详情

创建module

商品的详情页服务,命名为:leyou-goods-web

在这里插入图片描述

pom文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>myLeyou</artifactId>
        <groupId>com.leyou.parent</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.leyou.goods</groupId>
    <artifactId>leyou-goods-web</artifactId>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

        <dependency>
            <groupId>com.leyou.item</groupId>
            <artifactId>leyou-item-interface</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

    </dependencies>

</project>

启动类

@SpringBootApplication
@EnableFeignClients
@EnableDiscoveryClient
public class LeyouGoodsWebApplication {
   

    public static void main(String[] args) {
   
        SpringApplication.run(LeyouGoodsWebApplication.class,args);
    }
}

application.yaml

server:
  port: 8084
spring:
  application:
    name: goods-web
  thymeleaf:
    cache: false #关闭缓存,利于开发
  cloud:
    nacos:
      discovery:
        server-addr: ip地址:8848
        username: nacos
        password: nacos

页面模板

从leyou-portal中复制item.html模板到当前项目resource目录下的templates中:

在这里插入图片描述

1.2、页面跳转

1.2.1、修改页面跳转路径

首先需要修改搜索结果页的商品地址,目前所有商品的地址都是:http://www.leyou.com/item.html

应该跳转到对应的商品的详情页才对。

那么问题来了:商品详情页是一个SKU?还是多个SKU的集合?

在这里插入图片描述

通过详情页的预览,知道它是多个SKU的集合,即SPU。

所以,页面跳转时,应该携带SPU的id信息。

例如:http://www.leyou.com/item/2314123.html

这里就采用了路径占位符的方式来传递spu的id,打开search.html,修改其中的商品路径:

在这里插入图片描述

1.2.2、nginx反向代理

接下来,要把这个地址指向刚刚创建的服务:leyou-goods-web,其端口为8084

需要在nginx.conf中添加一段配置:

在这里插入图片描述

把以/item开头的请求,代理到机器的8084端口。

1.2.3、编写跳转controller

leyou-goods-web中编写controller,接收请求,并跳转到商品详情页:

@RestController
@RequestMapping("
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值