谷粒商城_08_商品首页+nginx+压力测试

本文介绍了谷粒商城系统首页的页面处理和静态资源管理,详细讲解了Nginx的配置、代理和与网关的结合使用。同时,探讨了使用Jmeter进行压力测试的过程,并分享了解决Jmeter Address Already in use错误的方法,最后讨论了性能优化策略,包括Nginx动静分离和三级分类的优化。
摘要由CSDN通过智能技术生成


在这里插入图片描述

商城系统首页

页面与静态资源处理

不使用前后端分离开发了,管理后台用vue

静态资源处理

1、nginx发给网关集群,网关再路由到微服务
2、静态资源放到nginx中,后面的很多服务都需要放到nginx中
3、index文件放到gulimall-product下的static文件夹
4、把index.html放到templates中

pom依赖

导入thymeleaf依赖、热部署依赖devtools使页面实时生效,修改之后ctrl+f9:build一下

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

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

关闭thymeleaf缓存,方便开发实时看到更新

  thymeleaf:
    cache: false
    suffix: .html # 后缀
    prefix: classpath:/templates/   # 前缀

web开发放到web包下,原来的controller是前后分离对接手机等访问的,所以可以改成app,对接app应用

启动测试:

渲染一级分类菜单

刚导入index.html时,里面的分类菜单都是写死的,我们要访问数据库拿到放到model中,然后在页面foreach填入

/**
 * @author ljy
 * @version 1.0.0
 * @Description 首页controller
 * @createTime 2021年12月16日 16:43:00
 */
@Controller
public class IndexController {
   
    @Autowired
    private CategoryService categoryService;


    @GetMapping({
   "/", "index.html"})
    public String getIndex(Model model) {
   
        // 获取所有的一级分类,getLevel1Catagories
        List<CategoryEntity> catagories = categoryService.getLevel1Catagories();
        // 放给页面取值
        model.addAttribute("catagories", catagories);
        // 视图解析器进行拼串,classpath:/templates/+返回值+.html
        return "index";
    }
}

页面遍历菜单数据

<html lang="en"  xmlns:th="http://www.thymeleaf.org">    # 导入语法

<li th:each="catagory:${catagories}" >
    <a href="#" class="header_main_left_a" ctg-data="3" th:attr="ctg-data=${catagory.catId}"><b th:text="${catagory.name}<
  • 12
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 18
    评论
评论 18
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

早上真起不来!

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值