搭建商品详情页工程
商品詳情
當用戶搜索到商品,肯定會點擊查看,就會進入商品詳情頁,接下來我們完成商品詳情頁的展示,
Thymeleaf
在商品詳情頁中,我們會使用到Thymeleaf來渲染頁面,所以需要先了解Thymeleaf的語法。
?
商品詳情頁服務
商品詳情瀏覽量比較大,并發高,我們會獨立開啟一個微服務,用來展示商品詳情。
創建module
商品的詳情頁服務,命名為:learn-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>learn</artifactId><groupId>com.learn.parent</groupId><version>1.0.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><groupId>com.learn.goods</groupId><artifactId>learn-goods-web</artifactId><version>1.0.0-SNAPSHOT</version><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</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.learn.item</groupId><artifactId>learn-item-interface</artifactId><version>1.0.0-SNAPSHOT</version></dependency></dependencies> </project>編寫啟動類
@SpringBootApplication @EnableDiscoveryClient @EnableFeignClients public class LeyouGoodsWebApplication {public static void main(String[] args) {SpringApplication.run(LeyouGoodsWebApplication.class, args);} }application.yml文件
server:port: 8084 spring:application:name: goods-webthymeleaf:cache: false eureka:client:service-url:defaultZone: http://127.0.0.1:10086/eurekainstance:lease-renewal-interval-in-seconds: 5 # 每隔5秒發送一次心跳lease-expiration-duration-in-seconds: 10 # 10秒不發送就過期頁面模板
我們從learn-portal中復制item.html模板到當前項目resource目錄下的templates中:
總結
- 上一篇: thymeleaf语法介绍
- 下一篇: 商品微服务添加api接口