Input type="date" 传递参数到后台

Spring 项目中,当前台input 设置为type=date时,传到后台的数据总是为null。
只需要在model实体类中的相应的字段上加上注解@DateTimeFormat即可。
但是有一点要注意,就是input的value值的格式必须和@DateTimeFormat中规定的一样
比如,前台打印出来input的value是yyyy-MM-dd,则@DateTimeFormat(“yyyy-MM-dd”)。
否则识别不出这个input对应的value,当然input的name必须和model中变量名的一样,如下:

页面:

<input type="date"	class="form-control form-control-sm" id="inpt_kfd_add" name="kickOffDate">

model类:
@Column(name = “bgn_date”)
@DateTimeFormat(pattern = “yyyy-MM-dd”)
private Date kickOffDate;

``` <%@ page language="java" import="test_package.*" import="java.util.*" import="java.sql.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <link rel="stylesheet" href="../style/certificate.css"> </head> <body> <% List<test_information> list = (List<test_information>)session.getAttribute("date"); %> <div class = "tit">查看凭证</div> <div class = "Ribbon"> <table> <tr> <td> <input type = "button" value = "传统记账" class = "R_button"> <form action = ""> <input type = "submit" value = "导出"> </form> <form action = ""> <input type = "hidden" id = "select"> <input type = "submit" value = "打印"> </form> <input type = "button" value = "模板" onclick ="template.show()"> </td> </tr> </table> </div> <div class="body"> <table class="cer" > <% for(test_information news:list) { %> <!-- 将每条记录分为两列展示 --> <tr> <td class = "zero_box"> <form><input type = "hidden" value = "<%=news.getTel() %>"> <input type = "radio" > </form> </td> <td class="first_box"> <%= news.getMaterial() %> <br/> <%= news.getStart_time() %> </td> <td class="second_box"> <%= news.getWashing_method() %> <br/> <%= news.getPrice() %> </td> <td class="third_box"> <form action =""> <input name = "id" value ="<%=news.getTel() %>" type = "hidden"> <input type ="submit" class = "func_button" value = "税费" ><br> <input type ="submit" class = "func_button" value = "查看凭证" ><br> <input type ="submit" class = "func_button" value = "删除凭证" > </form> <br/> </td> </tr> <% } %> </table> </div> </body> </html>```实现选择打印功能,即在表格中选中对应的项,点击打印可以打印出来,允许多选
03-18
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值