前言
本系列博客基于B站谷粒商城,只作为本人学习总结使用。这里我会比较注重业务逻辑的编写和相关配置的流程。有问题可以评论或者联系我互相交流。原视频地址谷粒商城雷丰阳版。本人git仓库地址Draknessssw的谷粒商城
首页查询一级分类
@GetMapping(value = {"/","index.html"})
private String indexPage(Model model) {
//1、查出所有的一级分类
List<CategoryEntity> categoryEntities = categoryService.getLevel1Categorys();
model.addAttribute("categories",categoryEntities);
return "index";
}
实现类
查询三级分类表中所有的一级分类
@Override
public List<CategoryEntity> getLevel1Categorys() {
System.out.println("getLevel1Categorys........");
long l = System.currentTimeMillis();
List<CategoryEntity> categoryEntities = this.baseMapper.selectList(
new QueryWrapper<CategoryEntity>().eq("parent_cid", 0));
System.out.println("消耗时间:"+ (System.currentTimeMillis() - l));
return categoryEntities;
}
域名环境
访问流程,由gulimal.com映射到本地虚拟机的ip地址,nginx接收来自gulimall.com的请求后转发给网关,由网关负载均衡的去向对应服务请求资源。
本地host文件中写访问映射规则
进入虚拟机nginx配置文件目录,将配置文件复制一份进行编写。例如将原来的默认配置复制改名成gulimall.conf
代理配置
上游网关服务器配置
配置网关
spring:
cloud:
gateway:
routes:
- id: gulimall_host_route
uri: lb://gulimall-product
predicates:
- Host=gulimall.com
此时再去配置nginx代理给网关的丢失的host信息