在 Thymeleaf 中编写 Date 类型时间选择器,可以使用 HTML5 中的 `` 元素。

示例代码:

<form>
    <label for='date'>选择日期:</label>
    <input type='date' id='date' name='date' th:field='*{date}' />
    <button type='submit'>提交</button>
</form>

在上述代码中,`th:field='*{date}'` 表示将表单中的 `date` 字段与模型中的 `date` 属性绑定,以便在提交表单时能够自动将日期值传递到后台。

注意:使用 `` 元素时,浏览器会自动根据用户所在时区来显示日期。因此,在处理日期时需要注意时区的问题。

Thymeleaf 日期选择器:使用 HTML5 <input type='date'> 元素

原文地址: https://www.cveoy.top/t/topic/nsQU 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录