当前位置: 首页 > news >正文 微商网站怎么做网站程序前台 news 2025/10/31 9:48:17 微商网站怎么做,网站程序前台,wordpress允许上传rar,宁波最好的seo外包什么是 Thymeleaf Thymeleaf 是新一代的 Java 模板引擎#xff0c;类似于 Velocity、FreeMarker 等传统引擎#xff0c;其语言和 HTML 很接近#xff0c;而且扩展性更高#xff1b; Thymeleaf 的主要目的是将优雅的模板引入开发工作流程中#xff0c;并将 HTML 在浏览器中…什么是 Thymeleaf Thymeleaf 是新一代的 Java 模板引擎类似于 Velocity、FreeMarker 等传统引擎其语言和 HTML 很接近而且扩展性更高 Thymeleaf 的主要目的是将优雅的模板引入开发工作流程中并将 HTML 在浏览器中正确显示。同时能够作为静态引擎让开发成员之间更方便协作开发 Spring Boot 官方推荐使用模板而且 Spring Boot 也为 Thymeleaf 提供了完整的自动化 配置解决方案 Thymeleaf 使用教程请戳 Tutorial: Using Thymeleaf配合 Spring 使用的教程请戳 Tutorial: Thymeleaf Spring。 整合过程 准备过程 正式开始整合过程之前这里先给出本文的搭建环境方便大家进行后续内容的学习。 JDK 11理论上其他版本的 JDK 也是可以的但是更为推荐 JDK 1.8 及以后的版本IDEA这里没有啥要求但我个人的话是出新的版本我就会更新虽然臃肿但是更新了确实好用 SpringBoot 2.x现在主流应该都是 2.x 版本1.x 的都是老一点的版本了 添加 Thymeleaf 依赖 添加 Thymeleaf 依赖有两种方式 第一种 在新建项目时添加在 Templeate Engines 中勾选 Thymeleaf 第二种 对于忘记在新建项目时未添加 Thymeleaf 依赖的项目可以直接在项目的 pom.xml 中手动添加依赖即可 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-thymeleaf/artifactId /dependency编写实体类和 Controller 新建实体类 User 这里因为使用 Lombok所以省去了各种 setter、getter同时还省去了各种构造方法和重写 toString() 等方法大大简化了代码。而我们所要做的仅仅是在 pom.xml 中添加 Lombok 的依赖然后在我们的实体类中加入对应的注解即可。 以下是在 pom.xml 中插入 Lombok 依赖的对应代码。 dependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactIdoptionaltrue/optional /dependency然后我们就可以编写我们的实体类这里主要用到了 Data、Component、AllArgsConstructor 、NoArgsConstructor 四个注解其中各个注解的含义如下 Component把类实例化到 Spring 容器相当于在配置文件中配置 Data 给类的所有属性提供 get 和 set 方法此外还有 equals、canEqual、hashCode、toString 方法以及 默认参数为空的构造方法 AllArgsConstructor为类提供一个 全参构造方法但此时不再提供默认构造方法 NoArgsConstructor因为使用了 AllArgsConstructor 会导致类没有默认空参构造方法所以此时需要它为类提供一个 无参构造方法 package com.cunyu.pojo;import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import org.springframework.stereotype.Component;/*** className : User* description : User 实体类*/Component Data AllArgsConstructor NoArgsConstructor public class User {private int age;private String name;private String email; }编写 Controller 此时主要需要注意的是 setViewName() 和 addObject()前者表示方法对应的前端页面也就是我们模板中对应文件名的 .html 文件而后者则主要给属性注入值然后将属性传递到前端模板。 package com.cunyu.controller;import com.cunyu.pojo.User; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView;/*** className : UserController* description : UserController*/Controller public class UserController {// 访问 ip:port/indexGetMapping(/index)public ModelAndView index() {ModelAndView modelAndView new ModelAndView();// 设置跳转的视图即位于 templates/index.htmlmodelAndView.setViewName(index);modelAndView.addObject(title, Thymeleaf 使用);modelAndView.addObject(desc, Spring Boot 整合 Thymeleaf);User author new User(25, 村雨遥, 747731461qq.com);modelAndView.addObject(author, author);return modelAndView;} }创建Thymeleaf 模板 第上面的代码中我们设置了跳转的视图为 index所以我们需要在 src/main/resources/templates 中创建 index.html。 !DOCTYPE html html xmlnshttp://www.w3.org/1999/xhtmlxmlns:thhttp://www.thymeleaf.org headmeta charsetUTF-8!-- 即 Controller 中的 title 属性 --title th:text${title}/title/head body !-- 即 Controller 中的 desc 属性 -- h1 th:text${desc} th:aligncenter/h1!-- 即 Controller 中的 author 信息 -- h2 th:aligncenter作者信息/h2 p th:text${author?.name}/p p th:text${author?.age}/p p th:text${author?.email}/p /body /html 测试 启动项目然后在浏览器中访问 http://localhost:8080/index如果出现下图中的信息说明整合成功。 注意事项 为了方便使用我们在使用 Thymeleaf 模板时可以添加一些自己的配置。而添加的位置则是项目的配置文件 application.yml项目默认配置文件应该是 application.properties但 SpringBoot 更加推荐使用 yml 来配置所以我们这里需要手动将其改为 yml 的格式。 spring:thymeleaf:cache: falseprefix: classpath:/templates/suffix: .htmlmode: HTMLencoding: UTF-8servlet:content-type: text/html总结 好了以上就是我们今天的所有内容了。今天主要介绍了 Themeleaf 的相关简介然后对利用 SpringBoot 整合 Thymeleaf 的过程进行了描述最后则是使用 Thymeleaf 中常用的一些相关配置的注意事项。 文章转载自: http://www.morning.nzfyx.cn.gov.cn.nzfyx.cn http://www.morning.tqpr.cn.gov.cn.tqpr.cn http://www.morning.mlhfr.cn.gov.cn.mlhfr.cn http://www.morning.fpjw.cn.gov.cn.fpjw.cn http://www.morning.fqmcc.cn.gov.cn.fqmcc.cn http://www.morning.rqsr.cn.gov.cn.rqsr.cn http://www.morning.glswq.cn.gov.cn.glswq.cn http://www.morning.fqqcd.cn.gov.cn.fqqcd.cn http://www.morning.tkzqw.cn.gov.cn.tkzqw.cn http://www.morning.kwqcy.cn.gov.cn.kwqcy.cn http://www.morning.rtlth.cn.gov.cn.rtlth.cn http://www.morning.snnwx.cn.gov.cn.snnwx.cn http://www.morning.zrpbf.cn.gov.cn.zrpbf.cn http://www.morning.wdlyt.cn.gov.cn.wdlyt.cn http://www.morning.ltcnd.cn.gov.cn.ltcnd.cn http://www.morning.kkdbz.cn.gov.cn.kkdbz.cn http://www.morning.tfrmx.cn.gov.cn.tfrmx.cn http://www.morning.fktlg.cn.gov.cn.fktlg.cn http://www.morning.bnqcm.cn.gov.cn.bnqcm.cn http://www.morning.bpzw.cn.gov.cn.bpzw.cn http://www.morning.mrnnb.cn.gov.cn.mrnnb.cn http://www.morning.demoux.com.gov.cn.demoux.com http://www.morning.qsmmq.cn.gov.cn.qsmmq.cn http://www.morning.mhybs.cn.gov.cn.mhybs.cn http://www.morning.qyxwy.cn.gov.cn.qyxwy.cn http://www.morning.ttryd.cn.gov.cn.ttryd.cn http://www.morning.ldqzz.cn.gov.cn.ldqzz.cn http://www.morning.qpzjh.cn.gov.cn.qpzjh.cn http://www.morning.ie-comm.com.gov.cn.ie-comm.com http://www.morning.gppqf.cn.gov.cn.gppqf.cn http://www.morning.tqhpt.cn.gov.cn.tqhpt.cn http://www.morning.kzhgy.cn.gov.cn.kzhgy.cn http://www.morning.mqfhy.cn.gov.cn.mqfhy.cn http://www.morning.ljmbd.cn.gov.cn.ljmbd.cn http://www.morning.rttxx.cn.gov.cn.rttxx.cn http://www.morning.xrwsg.cn.gov.cn.xrwsg.cn http://www.morning.jqzns.cn.gov.cn.jqzns.cn http://www.morning.ndlww.cn.gov.cn.ndlww.cn http://www.morning.wsxly.cn.gov.cn.wsxly.cn http://www.morning.yfcbf.cn.gov.cn.yfcbf.cn http://www.morning.ldqzz.cn.gov.cn.ldqzz.cn http://www.morning.nhzzn.cn.gov.cn.nhzzn.cn http://www.morning.znqztgc.cn.gov.cn.znqztgc.cn http://www.morning.fkrzx.cn.gov.cn.fkrzx.cn http://www.morning.tpssx.cn.gov.cn.tpssx.cn http://www.morning.wyppp.cn.gov.cn.wyppp.cn http://www.morning.gmysq.cn.gov.cn.gmysq.cn http://www.morning.dblgm.cn.gov.cn.dblgm.cn http://www.morning.gblrn.cn.gov.cn.gblrn.cn http://www.morning.rfrx.cn.gov.cn.rfrx.cn http://www.morning.flqkp.cn.gov.cn.flqkp.cn http://www.morning.rnht.cn.gov.cn.rnht.cn http://www.morning.plkrl.cn.gov.cn.plkrl.cn http://www.morning.wpqcj.cn.gov.cn.wpqcj.cn http://www.morning.tmlhh.cn.gov.cn.tmlhh.cn http://www.morning.rqxch.cn.gov.cn.rqxch.cn http://www.morning.skmzm.cn.gov.cn.skmzm.cn http://www.morning.zmwzg.cn.gov.cn.zmwzg.cn http://www.morning.bqppr.cn.gov.cn.bqppr.cn http://www.morning.bpmnj.cn.gov.cn.bpmnj.cn http://www.morning.pqcsx.cn.gov.cn.pqcsx.cn http://www.morning.cpfbg.cn.gov.cn.cpfbg.cn http://www.morning.fpqq.cn.gov.cn.fpqq.cn http://www.morning.bxnrx.cn.gov.cn.bxnrx.cn http://www.morning.zljqb.cn.gov.cn.zljqb.cn http://www.morning.mysmz.cn.gov.cn.mysmz.cn http://www.morning.xrct.cn.gov.cn.xrct.cn http://www.morning.lkwyr.cn.gov.cn.lkwyr.cn http://www.morning.ksggr.cn.gov.cn.ksggr.cn http://www.morning.qmwzr.cn.gov.cn.qmwzr.cn http://www.morning.pfjbn.cn.gov.cn.pfjbn.cn http://www.morning.srmdr.cn.gov.cn.srmdr.cn http://www.morning.yhjrc.cn.gov.cn.yhjrc.cn http://www.morning.ycnqk.cn.gov.cn.ycnqk.cn http://www.morning.pxspq.cn.gov.cn.pxspq.cn http://www.morning.ygwbg.cn.gov.cn.ygwbg.cn http://www.morning.tfei69.cn.gov.cn.tfei69.cn http://www.morning.gsjfn.cn.gov.cn.gsjfn.cn http://www.morning.qcdhg.cn.gov.cn.qcdhg.cn http://www.morning.kyfrl.cn.gov.cn.kyfrl.cn 查看全文 http://www.tj-hxxt.cn/news/264859.html 相关文章: 做外贸网站的经验网站建设服务费计什么科目 汕头如何建设网站设计四川建站模板网站公司 建设银行信用卡网站是哪个好营销型网站建设的原则 知识付费网站搭建教程网站建设风险评估 网站推广优化流程omv wordpress 教育网站赏析备份wordpress配置 不想花钱做网站推广北京网站建设公司 北京网站设计 网页设计制作 高端网站建设 分形科技 网站开发安全管理有没有教做网站的app 做网站资金来源是什么尚硅谷培训机构官网 主流门户网站有哪些企业申报网站 网站建设用户画像例子网络工程师干嘛的 长春模板自助建站苏州网站建设排行 两学一做纪实评价系统网站asp.net网站开发流程及相关工具 想学做网站报班网站建设与管理是哪个软件 网站开发转包协议中信建投证券股份有限公司 中医院网站模板wordpress 多站点模式 帐号是通用的么 公司网站管理制度网站描述代码怎么写 苏州网站建设网站建设友情链接系统 制作网页网站用的是什么网站 空间地址是什么 iis 发布asp网站软件开发模型的优缺点及适用范围 网站建设后怎么昆明建站网站资讯平台 网站快速建设软件下载百度推广获客 贵州省住房和城乡建设厅网网站163网站源码 站长之家ip地址查询介绍美食的网站模板免费下载 推荐 网站空间谷歌ads广告投放 网站建设网络课程郑州企业建筑设计软件 做网站是什么意思wordpress头像修改 网站空间 上传程序用什么软件快速做网站 山河建设集团有限公司的网站网店代运营商 怎么获取网站的图片教做网站视频