phymeleaf 除取整_thymeleaf学习笔记

常用代码:

格式化显示当前日期

if判断

打印订单

循环列表

服务器:

public String printOrder(Long id, ModelMap mmap) {

String[] fileNames=orderPesticide.getFileName().split(",");

mmap.put("fileNames", fileNames);

return prefix + "/printOrder";

}

页面:

数据包文件名:

服务器:

publicString orderDetail(Long id, ModelMap mmap) {

List details = orderPesticideDetailService.selectOrderPesticideDetailList(orderPesticideDetail);

mmap.put("details", details);return prefix + "/orderDetail";

}

页面:

1.${@dict.hello().fatherName} 显示对象的属性

2.${@dict.hello()[0].fatherName} 显示列表对象的属性

3.

服务器:

publicString customerContact(String customerid, Model model) {

model.addAttribute("customerid", customerid);return prefix + "/customerContact";

}

页面:

th:value="${customerid}"是输出到value

th:text="${customerid}"是输出到text,如:

text

-------------------------------------------------------------------------------------------------------------------------------------------

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Thymeleaf 是一种 Java 模板引擎,可以用于 Web 应用程序的开发。它允许开发人员使用 HTML 模板创建动态内容,并将其与 Java 代码集成。使用 Thymeleaf,可以轻松地将数据绑定到 HTML 页面上,并根据需要进行格式化、转换和验证。 下面是使用 Thymeleaf 的基本步骤: 1. 添加 Thymeleaf 依赖项 在 Maven 项目中,需要在 pom.xml 文件中添加以下依赖项: ``` <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> ``` 2. 创建 Thymeleaf 模板 在 src/main/resources/templates 目录下创建一个 HTML 文件,例如 index.html。在 HTML 文件中添加 Thymeleaf 标记,例如: ``` <!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head> <title>Thymeleaf Example</title> </head> <body> <h1 th:text="${title}">Default Title</h1> </body> </html> ``` 在上面的例子中,使用了 Thymeleaf 的表达式 ${title} 来绑定一个标题。如果没有传递标题参数,则默认使用 "Default Title"。 3. 创建控制器 在控制器类中创建一个处理请求的方法,并将模板名称和数据传递给 Thymeleaf 引擎。例如: ``` @Controller public class MyController { @GetMapping("/") public String index(Model model) { model.addAttribute("title", "Welcome to Thymeleaf!"); return "index"; } } ``` 在上面的例子中,使用了 @GetMapping 注释来处理 GET 请求,并将标题传递给 Thymeleaf 模板。 4. 运行应用程序 运行应用程序后,访问 http://localhost:8080/ 将显示包含标题的 HTML 页面。如果没有传递标题参数,则默认使用 "Default Title"。 这就是使用 Thymeleaf 的基本步骤。除此之外,Thymeleaf 还提供了许多其他功能,例如条件逻辑、迭代、国际化等。可以查看 Thymeleaf 文档以了解更多信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值