当前位置:网站首页>JSTL 自定义标签
JSTL 自定义标签
2022-06-11 13:48:00 【梁云亮】
说明
JSTL默认不支持LocalDate和LocalDateTime,在JSP中自定义显示LocalDate和LocalDateTime,需要通过自定义标签实现。
第一步:创建具体进行转换的工具类
- LocalDateTimeFormatter
public class LocalDateTimeFormatter {
public static String formatLocalDateTime(LocalDateTime localDateTime, String pattern) {
return localDateTime.format(DateTimeFormatter.ofPattern(pattern));
}
}
- LocalDateFormatter
public class LocalDateFormatter {
public static String formatLocalDate(LocalDate localDate, String pattern) {
return localDate.format(DateTimeFormatter.ofPattern(pattern));
}
}
第二步:在WEB-INF目录下创建tld文件
<?xml version="1.0" encoding="UTF-8" ?>
<taglib xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd" version="2.1">
<tlib-version>1.0</tlib-version>
<short-name>Custom_Functions</short-name>
<uri>http://wego.com/format</uri>
<function>
<name>formatLocalDateTime</name>
<function-class>com.wego.formatter.LocalDateTimeFormatter</function-class>
<function-signature>java.lang.String formatLocalDateTime(java.time.LocalDateTime, java.lang.String)</function-signature>
</function>
<function>
<name>formatLocalDate</name>
<function-class>com.wego.formatter.LocalDateFormatter</function-class>
<function-signature>java.lang.String formatLocalDate(java.time.LocalDate, java.lang.String)</function-signature>
</function>
</taglib>
第三步:测试
- 服务器端数据
request.setAttribute("localDate", LocalDate.now());
request.setAttribute("localDateTime", LocalDateTime.now());
- 页面使用
日期:${
f:formatLocalDate(localDate, 'yyyy-MM*dd')}
日期时间:${
f:formatLocalDateTime(localDateTime, 'yyyy-MM-dd HH:mm:ss')}
边栏推荐
- The end of an era! After ten years, Wu Enda's classic machine learning course closed its registration this month and launched a new course
- 关于#php#的问题:php写的原来的部署环境是在phpstudy里面进行部署的,php+MySQL+Apache但是由于每次都得保证电脑开着
- Unsealing easy QF PDA helps enterprises improve ERP management
- 无延时/无延迟视频直播实例效果案例
- cadence SPB17.4 - group operation(add to group, view group list, delete group)
- From real-time computing to streaming data warehouse, where will Flink go next?
- Hashicopy之nomad应用编排方案06(配置task)
- Question bank and answers for 2022 tool fitter (intermediate) operation certificate examination
- YOLOv3学习笔记:YOLOv3的模型结构
- Setting tcp/ip network in Debian
猜你喜欢

cadence SPB17.4 - group operation(add to group, view group list, delete group)

如何写出高性能代码(四)优化数据访问

Energy storage operation and configuration analysis of high proportion wind power system (realized by Matlab)

How to quickly make the title and ending with one click?

About uni app configuration, app does not display the top title bar setting

LNMP deployment

Microsoft exposes another "scandal": watching VR porn in the office, "the father of hololens" is about to leave!

Ali talked about the use of strategic mode in the project

程序员到了35岁之后的一些转型思考

六.开发记录之实验室服务器LXD部署
随机推荐
Explain in detail the differences between real participation formal parameters in C language
Code comparison tool, I use these six
RS485(Modbus RTU)工业RFID读写器CK-FR03-A01与PLC三菱FX5U的通讯操作说明
jdbctemplate数据后台管理,不知道为什么添加用户的时候显示roleId为空
Hashicopy之nomad应用编排方案06(配置task)
Implementation of VGA protocol based on FPGA
cadence SPB17.4 - group operation(add to group, view group list, delete group)
Question bank and answers for 2022 tool fitter (intermediate) operation certificate examination
Teatalk · online speech record | complete! It is important to select the right data migration strategy for safe cloud deployment
Kubernetes binary installation (v1.20.15) (VII) plug a work node
风电随机性动态经济调度模型(Matlab代码实现)
Explanation of waitgroup usage in go language learning
JDBC连接池去做批量导入,每次运行500万数据,但是在中间就会出各种问题
[signal processing] digital signal processing matlab design with GUI interface and report
Terraform + Ansible实现基础设施及配置管理
Interview to build an aircraft carrier, screw on the job, pay
VIM secondary replacement
Microsoft exposes another "scandal": watching VR porn in the office, "the father of hololens" is about to leave!
AGV机器人RFID传感器CK-G06A与西门子1200PLC应用手册
Network information system emergency response