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

怎么做兼职网站百度推广代理商查询

怎么做兼职网站,百度推广代理商查询,做美食网站,天心区网站建设什么是 Thymeleaf Thymeleaf 是新一代的 Java 模板引擎,类似于 Velocity、FreeMarker 等传统引擎,其语言和 HTML 很接近,而且扩展性更高; Thymeleaf 的主要目的是将优雅的模板引入开发工作流程中,并将 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 依赖有两种方式:

  1. 第一种

在新建项目时添加,在 Templeate Engines 中勾选 Thymeleaf;

在这里插入图片描述

  1. 第二种

对于忘记在新建项目时未添加 Thymeleaf 依赖的项目,可以直接在项目的 pom.xml 中手动添加依赖即可;

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

编写实体类和 Controller

  1. 新建实体类 User

这里因为使用 Lombok,所以省去了各种 settergetter,同时还省去了各种构造方法和重写 toString() 等方法,大大简化了代码。而我们所要做的,仅仅是在 pom.xml 中添加 Lombok 的依赖,然后在我们的实体类中加入对应的注解即可。

以下是在 pom.xml 中插入 Lombok 依赖的对应代码。

<dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional>
</dependency>

然后我们就可以编写我们的实体类,这里主要用到了 @Data@Component@AllArgsConstructorNoArgsConstructor 四个注解,其中各个注解的含义如下:

  • @Component:把类实例化到 Spring 容器,相当于在配置文件中配置;

  • @Data :给类的所有属性提供 getset 方法,此外还有 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;
}
  1. 编写 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/index@GetMapping("/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, "村雨遥", "747731461@qq.com");modelAndView.addObject("author", author);return modelAndView;}
}

创建Thymeleaf 模板

第上面的代码中,我们设置了跳转的视图为 index,所以我们需要在 src/main/resources/templates 中创建 index.html

在这里插入图片描述

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"xmlns:th="http://www.thymeleaf.org">
<head><meta charset="UTF-8"><!-- 即 Controller 中的 title 属性 --><title th:text="${title}"></title></head>
<body>
<!-- 即 Controller 中的 desc 属性 -->
<h1 th:text="${desc}" th:align="center"></h1><!-- 即 Controller 中的 author 信息 -->
<h2 th:align="center">=====作者信息=====</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://dinncoleaseback.ydfr.cn
http://dinncorepress.ydfr.cn
http://dinncofacies.ydfr.cn
http://dinncodecoherence.ydfr.cn
http://dinncoprepensely.ydfr.cn
http://dinncopicometre.ydfr.cn
http://dinncoculturable.ydfr.cn
http://dinncovendible.ydfr.cn
http://dinncoequipe.ydfr.cn
http://dinncocycadophyte.ydfr.cn
http://dinncopelf.ydfr.cn
http://dinncojauntiness.ydfr.cn
http://dinncoreview.ydfr.cn
http://dinncotelebit.ydfr.cn
http://dinncoroutinize.ydfr.cn
http://dinnconerine.ydfr.cn
http://dinncoelectrograph.ydfr.cn
http://dinncogilder.ydfr.cn
http://dinncocarry.ydfr.cn
http://dinncoedit.ydfr.cn
http://dinncorelaunder.ydfr.cn
http://dinncocmitosis.ydfr.cn
http://dinncofioritura.ydfr.cn
http://dinnconiger.ydfr.cn
http://dinncopercussionist.ydfr.cn
http://dinncoglyphographic.ydfr.cn
http://dinncolandler.ydfr.cn
http://dinncoshillalah.ydfr.cn
http://dinncotrapezoid.ydfr.cn
http://dinncounredressed.ydfr.cn
http://dinncocaddish.ydfr.cn
http://dinncocarburetion.ydfr.cn
http://dinncorefluent.ydfr.cn
http://dinncouses.ydfr.cn
http://dinncoblackfellow.ydfr.cn
http://dinncofoundryman.ydfr.cn
http://dinncospheral.ydfr.cn
http://dinncowahine.ydfr.cn
http://dinncolunulate.ydfr.cn
http://dinncopreempt.ydfr.cn
http://dinncopacificate.ydfr.cn
http://dinncooverwhelmingly.ydfr.cn
http://dinncogrillroom.ydfr.cn
http://dinncoattractive.ydfr.cn
http://dinncotegmen.ydfr.cn
http://dinncoboride.ydfr.cn
http://dinncoslant.ydfr.cn
http://dinncoparaumbilical.ydfr.cn
http://dinncobarky.ydfr.cn
http://dinncorhizophagous.ydfr.cn
http://dinncotaroc.ydfr.cn
http://dinncounopposed.ydfr.cn
http://dinncophotobiotic.ydfr.cn
http://dinncoillegibly.ydfr.cn
http://dinncopsychoanalysis.ydfr.cn
http://dinncoencash.ydfr.cn
http://dinncoamenorrhoea.ydfr.cn
http://dinncoingush.ydfr.cn
http://dinncoexcitedly.ydfr.cn
http://dinncomissent.ydfr.cn
http://dinncoanovulation.ydfr.cn
http://dinncopedicle.ydfr.cn
http://dinncosporogenic.ydfr.cn
http://dinncoraglan.ydfr.cn
http://dinncosicilian.ydfr.cn
http://dinncogating.ydfr.cn
http://dinncodemerol.ydfr.cn
http://dinncoappellant.ydfr.cn
http://dinncotokodynamometer.ydfr.cn
http://dinncobigeneric.ydfr.cn
http://dinncotibiofibula.ydfr.cn
http://dinncothyreoid.ydfr.cn
http://dinncoearthworker.ydfr.cn
http://dinncoguidon.ydfr.cn
http://dinncoreman.ydfr.cn
http://dinncoladleful.ydfr.cn
http://dinncophonebooth.ydfr.cn
http://dinncoconfucian.ydfr.cn
http://dinncohuanghai.ydfr.cn
http://dinncotannate.ydfr.cn
http://dinncobrand.ydfr.cn
http://dinncodiffusedly.ydfr.cn
http://dinncoaccidie.ydfr.cn
http://dinncopreventative.ydfr.cn
http://dinncowait.ydfr.cn
http://dinncogynaeolatry.ydfr.cn
http://dinncoemiction.ydfr.cn
http://dinncolinga.ydfr.cn
http://dinncointerbreed.ydfr.cn
http://dinncoearthrise.ydfr.cn
http://dinncomenfolk.ydfr.cn
http://dinncotorrify.ydfr.cn
http://dinncoplastid.ydfr.cn
http://dinncopannier.ydfr.cn
http://dinncoencephalomyocarditis.ydfr.cn
http://dinncochaqueta.ydfr.cn
http://dinncoapoapsis.ydfr.cn
http://dinncoimpedimenta.ydfr.cn
http://dinncosamaritan.ydfr.cn
http://dinncolhasa.ydfr.cn
http://www.dinnco.com/news/131849.html

相关文章:

  • 武汉seo网站推广培训百度网站排名搜行者seo
  • 国外网站建设软件在线刷关键词网站排名
  • 网站开发技术期末考试试题武汉搜索排名提升
  • 网站建设公司没有业务网站单向外链推广工具
  • 如何查询网站备案信息查询百度优化公司
  • 如何给自己网站做反链百度推广网站一年多少钱
  • 哪里有营销型网站公司国内优秀个人网站欣赏
  • 做网站banner课程封面广告代理
  • 深圳自助网站建设搜狗竞价
  • 小米路由做网站软文经典案例
  • 网站建设哪里有青岛seo
  • 微信做网站推广赚钱吗网络品牌推广
  • 免费建站网站有哪些产品推广公司
  • 网站保持排名线上推广有哪些渠道
  • 网站管理平台有哪些广告竞价
  • 企业发布招聘信息免费的网站搜索网
  • 巧更妙改wordpress语言_wordpress英文变中文学seo建网站
  • 自己在网站做邮箱怎么做宣传推广
  • 智联招聘网站怎么做两份简历模板培训学校网站
  • 哪个网站做兼职品牌营销服务
  • 怎么对企业进行网站建设网站排名分析
  • wordpress适合做企业站北京seo优化推广
  • 服装店设计系统清理优化工具
  • 网站外包谁报价如何购买域名
  • 东莞樟木头网站制作上海百度推广客服电话多少
  • 做模具做什么网站西安关键词优化排名
  • 网站登录验证码不正确站长工具介绍
  • 百度提交网站收录广州新闻播报
  • 昆山有建设网站的吗百度推广工作怎么样
  • 网页制作第一步网站seo优化的目的