当前位置: 首页 > wzjs >正文

做网站的工资高网站首屏高度

做网站的工资高,网站首屏高度,为什么网站要域名,上传wordpress到空间引入thymeleaf 介绍 Thymeleaf 是一款用于 Web 和独立环境的现代化服务器端 Java 模板引擎,主要用于生成动态 HTML 页面、电子邮件、XML 等。它的核心设计目标是提供优雅且自然的模板语法,同时保持与静态 HTML 的高度兼容性,使前端开发人员…
引入thymeleaf
介绍

Thymeleaf 是一款用于 Web 和独立环境的现代化服务器端 Java 模板引擎,主要用于生成动态 HTML 页面、电子邮件、XML 等。它的核心设计目标是提供优雅且自然的模板语法,同时保持与静态 HTML 的高度兼容性,使前端开发人员可以直接在浏览器中预览模板效果,而无需依赖后端服务。

我们的商城系统本应该也是前后端分离的,就像后台管理系统那样,然而出于教学考虑,前后端分离的话就会屏蔽掉很多细节,所以我们进行服务端的页面渲染式开发(有点儿类似freemarker)

动静分离:nginx在后面部署的时候,我们可以将微服务中的页面的静态资源部署到nginx中。分担微服务的压力。

静指的是:图片、js、css等静态资源(以实际文件存在的方式)

每一个微服务只来管理自己的页面,最终做到每一个微服务都可以独立部署、运行、升级。

每个微服务都是独立自治的,每一个微服务的数据库、技术都是自治的。不一定商品服务用java开发,用php、js都可以,无论是从技术层面、架构层面还是业务都是独立自治的。

image-20250327083114164

引入

导入依赖:

        <!--模板引擎--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency>

修改application.yml文件

spring:thymeleaf:cache: false #关闭缓存,为了在生产环境下可以实时看到数据mvc:static-path-pattern: /static/** # 加载不出样式文件时需要加上这个

将静态资源放到static目录下,同时页面html文件放入到templates文件夹下面去,因为spring boot访问项目的时候默认会找index.html

image-20250327083545065

静态资源的访问

image-20250327083744509

引入dev-tools依赖,使得修改后不重启服务器实时更新

        <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><optional>true</optional></dependency>
商城一级分类渲染
package com.atguigu.gulimall.product.web;import com.atguigu.gulimall.product.entity.CategoryEntity;
import com.atguigu.gulimall.product.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;import java.util.List;@Controller
public class IndexController {@AutowiredCategoryService categoryService;@GetMapping({"/","/index.html"}) // 配置访问localhost:10000/或者localhost:10000/index.html来到首页的映射public String indexPage(Model model){ // 查出一级类目,使用Model对象封装// 1.查出所有1级分类List<CategoryEntity> entities = categoryService.getLevel1Categorys();// 返回视图地址// 使用视图解析器进行拼串model.addAttribute("categories",entities);return "index";}
}@Overridepublic List<CategoryEntity> getLevel1Categorys() {return baseMapper.selectList(new QueryWrapper<CategoryEntity>().eq("parent_cid",0));}
商城二三级分类渲染

修改js文件,使得页面不在获取静态数据

image-20250327084121045

根据提供的静态json数据文件封装对应的接口返回类

image-20250327084220930

import lombok.Data;
import java.util.List;/*** 二三级分类id,首页分类数据**/
@Data
public class Catalog2VO {/*** 一级父分类的id*/private String catalog1Id;/*** 三级子分类*/private List<Category3Vo> catalog3List;private String id;private String name;/*** 三级分类vo*/@Datapublic static class Category3Vo {/*** 父分类、二级分类id*/private String catalog2Id;private String id;private String name;}
}

编写分类数据获取接口

@Controller
public class IndexController {@AutowiredCategoryService categoryService;@GetMapping({"/","/index.html"})public String indexPage(Model model){// 1.查出所有1级分类List<CategoryEntity> entities = categoryService.getLevel1Categorys();// 返回视图地址// 使用视图解析器进行拼串model.addAttribute("categories",entities);return "index";}/*** 获取分类数据* @return*/@ResponseBody // 返回的是数据而不是页面,要标上注解@ResponseBody@GetMapping("/index/catalog.json")public Map<String, List<Catalog2VO>> getCatalogJson(){Map<String, List<Catalog2VO>> map = categoryService.getCatalogJson();return map;}
}
    @Overridepublic Map<String, List<Catalog2VO>> getCatalogJson() {// 1.查出所有1级分类List<CategoryEntity> leve1Categorys = getLevel1Categorys();// 2.封装数据Map<String, List<Catalog2VO>> collect = leve1Categorys.stream().collect(Collectors.toMap(k -> k.getCatId().toString(), v -> {// 2.1 每一个一级分类,查到这个一级分类的二级分类List<CategoryEntity> categoryEntities = baseMapper.selectList(new QueryWrapper<CategoryEntity>().eq("parent_cid", v.getCatId()));// 2.2 封装上面的结果List<Catalog2VO> catalog2VOS = null;if (categoryEntities != null) {catalog2VOS = categoryEntities.stream().map(l2 -> {Catalog2VO catalog2VO = new Catalog2VO();catalog2VO.setId(l2.getCatId().toString());catalog2VO.setName(l2.getName());catalog2VO.setCatalog1Id(v.getCatId().toString());// 找当前二级分类的三级分类封装成voList<CategoryEntity> level3Category = baseMapper.selectList(new QueryWrapper<CategoryEntity>().eq("parent_cid", l2.getCatId()));if (level3Category != null) {List<Catalog2VO.Category3Vo> collect3 = level3Category.stream().map(l3 -> {return new Catalog2VO.Category3Vo(catalog2VO.getId(), l3.getCatId().toString(),l3.getName());}).collect(Collectors.toList());catalog2VO.setCatalog3List(collect3);}return catalog2VO;}).collect(Collectors.toList());}return catalog2VOS;}));return collect;}

文章转载自:

http://XuMcBNTh.bpmtg.cn
http://1ZCxRIHH.bpmtg.cn
http://L6tqnOJS.bpmtg.cn
http://26oTzRAP.bpmtg.cn
http://itfWIKgn.bpmtg.cn
http://j1f4T1C3.bpmtg.cn
http://9q4Cywls.bpmtg.cn
http://t1tuZvpq.bpmtg.cn
http://CdlwtTzw.bpmtg.cn
http://sDy1I6RN.bpmtg.cn
http://HqDny9Pa.bpmtg.cn
http://z56EKCPG.bpmtg.cn
http://MFKH3Jrs.bpmtg.cn
http://VkWaAgQF.bpmtg.cn
http://fNZLMv1q.bpmtg.cn
http://aHKXR9Rq.bpmtg.cn
http://5bqNPwaj.bpmtg.cn
http://R29GjEHf.bpmtg.cn
http://tM0vXbSo.bpmtg.cn
http://NUo0RXe1.bpmtg.cn
http://sREDoH90.bpmtg.cn
http://SB4tRGoV.bpmtg.cn
http://E13fZWqG.bpmtg.cn
http://bzOYZwfl.bpmtg.cn
http://GC3hlOC5.bpmtg.cn
http://gnvUhz8S.bpmtg.cn
http://Hbz5m3MM.bpmtg.cn
http://VJIBAWRQ.bpmtg.cn
http://X1WZ2bjm.bpmtg.cn
http://i6V12Yhv.bpmtg.cn
http://www.dtcms.com/wzjs/706090.html

相关文章:

  • 视频网站如何做营销WordPress4.8中文的把
  • 网站建设网络推广加盟渭南建站
  • 为什么做的网站在浏览器搜不到牡丹江免费信息网
  • 南昌网站建设哪里好宣传产品的方式
  • 麦片网站建设哈尔滨百度推广排名
  • 盐城网站建设官网深圳电子商务网站 开发
  • wordpress点评站食品商务网-网站建设
  • 企业网站开发服务合同母婴网站模板
  • 成都市企业网站建设公众号怎么做文章
  • 网站建设审批表湖南优化电商服务有限公司
  • 霸州 网络 网站建设企业网络安全管理
  • 蚌埠网站建设网站大学生水果预定配送网站建设的项目规划书
  • 深圳罗湖区网站开发公司电子商务课程内容
  • 任丘市建设局网站潼关县住房和城乡建设局网站
  • 泰安哪里做网站做网站设计
  • 新网站如何做推广软文郑州画册设计公司
  • 鱼台做网站多少钱网站一定要服务器吗
  • 重庆seo推广免费优化网站排名
  • 菜鸟怎么做网站网上做网站网站吗
  • 哪里找人做网站wordpress wlw
  • 做网站赚什么钱西部空间怎样上传网站
  • 网站建设做什么下载应用
  • 拓客网站建设企业营销型网站特点
  • 东莞政务网站建设方案ppt模板免费模板下载
  • 徐州公司网站建设培训类网站开发
  • 怀柔手机网站建设网站访问量过大
  • 华东网站建设品牌设计师
  • 商城网站服务器租用佛山网站建设服务器
  • 生鲜网站建设费用免费购物网站系统
  • 使用网站做图片的软件免费