NutzCN Logo
问答 ajax提交日期格式
发布于 2700天前 作者 大豪豪 1822 次浏览 复制 上一个帖子 下一个帖子
标签:

前台input 类型date
用ajax提交日期格式数据
传到后台报错
org.nutz.castor.FailToCastObjectException: 'startDat' to java.util.Date
at org.nutz.castor.castor.DateTimeCastor.toDate(DateTimeCastor.java:17)
at org.nutz.castor.castor.String2Datetime.cast(String2Datetime.java:12)
at org.nutz.castor.castor.String2Datetime.cast(String2Datetime.java:5)
at org.nutz.castor.Castors.cast(Castors.java:252)
at org.nutz.mvc.adaptor.convertor.DateParamConvertor.convert(DateParamConvertor.java:39)
at org.nutz.mvc.adaptor.injector.ObjectPairInjector.get(ObjectPairInjector.java:62)
at org.nutz.mvc.adaptor.AbstractAdaptor.adapt(AbstractAdaptor.java:257)
at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:28)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at com.kf.dms.mvc.LogTimeProcessor.process(LogTimeProcessor.java:27)
at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202)
at com.kf.dms.web.filter.DmsNutzFilter.doFilter(DmsNutzFilter.java:47)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2441)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2430)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: Unexpect date format 'startDat'
at org.nutz.lang.Lang.makeThrow(Lang.java:132)
at org.nutz.lang.Times.ams(Times.java:204)
at org.nutz.lang.Times.ams(Times.java:118)
at org.nutz.lang.Times.D(Times.java:321)
at org.nutz.castor.castor.DateTimeCastor.toDate(DateTimeCastor.java:11)

14 回复

回复按钮旁边就是插入代码的按钮,把上面的报错信息重新发一次

2017-08-01 14:31:30,551 [INFO-Druid-ConnectionPool-Log-1938145399:610614] com.alibaba.druid.pool.DruidDataSourceStatLoggerImpl.log(DruidDataSourceStatLoggerImpl.java:77) {"url":"jdbc:mysql://192.168.1.134:3306/dmsv2?useUnicode=true&characterEncoding=UTF-8","dbType":"mysql","name":"DataSource-1938145399","activeCount":0,"poolingCount":1,"connectCount":0,"closeCount":0}
2017-08-01 14:31:33,091 [DEBUG-http-apr-8080-exec-2:613154] org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:101) Found mapping for [POST] path=/ard/n/common/reimburse/queryReimburse : ArdReimburseMouble.queryReimburse(ArdReimburseMouble.java:58)
2017-08-01 14:31:33,093 [DEBUG-http-apr-8080-exec-2:613156] org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) Get 'ardReimburseMouble'<class com.kf.dms.modules.ard.common.ArdReimburseMouble>
2017-08-01 14:31:33,095 [DEBUG-http-apr-8080-exec-2:613158] com.kf.dms.web.filter.wds.ParamsLogFilter.match(ParamsLogFilter.java:31) | ����[startDat]��ֵΪ | startDat |
2017-08-01 14:31:33,096 [DEBUG-http-apr-8080-exec-2:613159] com.kf.dms.web.filter.wds.ParamsLogFilter.match(ParamsLogFilter.java:31) | ����[AuditStatus]��ֵΪ | AuditStatus |
2017-08-01 14:31:33,100 [DEBUG-http-apr-8080-exec-2:613163] com.kf.dms.mvc.LogTimeProcessor.process(LogTimeProcessor.java:31) [POST]URI=/Sueng/ard/n/common/reimburse/queryReimburse  7ms
2017-08-01 14:31:33,101 [WARN-http-apr-8080-exec-2:613164] org.nutz.mvc.impl.processor.FailProcessor.process(FailProcessor.java:28) Error@/ard/n/common/reimburse/queryReimburse :
org.nutz.castor.FailToCastObjectException: 'startDat' to java.util.Date
	at org.nutz.castor.castor.DateTimeCastor.toDate(DateTimeCastor.java:17)
	at org.nutz.castor.castor.String2Datetime.cast(String2Datetime.java:12)
	at org.nutz.castor.castor.String2Datetime.cast(String2Datetime.java:5)
	at org.nutz.castor.Castors.cast(Castors.java:252)
	at org.nutz.mvc.adaptor.convertor.DateParamConvertor.convert(DateParamConvertor.java:39)
	at org.nutz.mvc.adaptor.injector.ObjectPairInjector.get(ObjectPairInjector.java:62)
	at org.nutz.mvc.adaptor.AbstractAdaptor.adapt(AbstractAdaptor.java:257)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:28)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at com.kf.dms.mvc.LogTimeProcessor.process(LogTimeProcessor.java:27)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202)
	at com.kf.dms.web.filter.DmsNutzFilter.doFilter(DmsNutzFilter.java:47)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
	at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2441)
	at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2430)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: Unexpect date format 'startDat'
	at org.nutz.lang.Lang.makeThrow(Lang.java:132)
	at org.nutz.lang.Times.ams(Times.java:204)
	at org.nutz.lang.Times.ams(Times.java:118)
	at org.nutz.lang.Times.D(Times.java:321)
	at org.nutz.castor.castor.DateTimeCastor.toDate(DateTimeCastor.java:11)
	... 42 more

@Param写了啥

写了一个对象 里面的日期是date格式的

public ArdReturns queryReimburse(@Param("..")RecordParams params) {
		System.out.println(params.getStartDat()+"......................1");
		return ardReimburService.selectreimburService(params);
	}



package com.kf.dms.pojo.params.ard;

import java.util.Date;

import com.kf.dms.pojo.common.ArdParams;

public class RecordParams extends ArdParams{
	/** 开始时间  */
	private Date startDat;
	
	/** 结束时间 */
	private Date endDat;
	/**审核状态 **/
	private Integer AuditStatus;
	public Date getStartDat() {
		return startDat;
	}
	public void setStartDat(Date startDat) {
		this.startDat = startDat;
	}
	public Date getEndDat() {
		return endDat;
	}
	public void setEndDat(Date endDat) {
		this.endDat = endDat;
	}
	public Integer getAuditStatus() {
		return AuditStatus;
	}
	public void setAuditStatus(Integer auditStatus) {
		AuditStatus = auditStatus;
	}
	

}

我觉得页面传过的值是错的, 检查一下, 理应传startDat变量, 结果写了 "startDat"

这是前端的Ajax

<%@ page language="java"  pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>

<!DOCTYPE html>
<html>
  <head>
    <title>baoxiao.html</title>
	
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    
 <link rel="stylesheet" type="text/css" href="./css/baixoiaozt.css">
      <script type="text/javascript" src="./js/jquery-2.1.4.js"></script>
       <script type="text/javascript" src="./js/jquery-1.8.3.min.js"></script>
       <script type="text/javascript">
       
    
         function submi(){
         var startDat=$("#i").val();
         var AuditStatus=$("#a").val();
           $.ajax({
             type: "post",
             url: "ard/n/common/reimburse/queryReimburse",
             data: {startDat:"startDat",AuditStatus:"AuditStatus"},
             success: function(data){
               alert(data.Amount);
             }
                         });
       }
       </script>
  </head>
  
  <body>
            <div id="d" >报销列表</div>
      		<div id="im"><img src="./image/zkh.png" height="40px" width="40px" ></div>
      		<div id="im1"><a href="baoxiaoXZ.html" target="_self"><img src="./image/bx_j.png" height="40px" width="40px" ></a></div>
      		<div class="div1">
      		<form action="" method="post"> 
      		<table class="tb" >
      		<tr>
      		<td><span style="font-size: 26px;margin-left: 20%" >时间</span></td>
      		<td><input type="date" name="startDat" id="i"></td>
      		<td><span style="font-size: 26px;margin-left: 20%" >状态</span></td>
      		<td><select id="a" name=AuditStatus style="width:200px ;height:40px;  margin-right: 50%; font-size: 26px;"> 
					<option   value="0">未审核</option> 
					<option    value="1">已审核</option> 
				</select></td>
      		<td><button type="submit" style=" border-radius: 5px; background:#0099FF; color: #FFFFFF; border: 1px  #555 solid;height:30px;width: 80px; margin-right: 100%" onclick="submi()">查询</button></td>
      		</tr>
      		</table>
      		</form>
      		</div>
      		<div>
      		<table class="table" >
				<tr class="tr"> 
							<td rowspan="2"  style="border-top:1px solid #BBB; border-bottom: 1px solid #BBB;"><img src="./image/small/bx_cl.png" style="margin-left: 40%; height:50px; width:70px;margin-top: 5%;"></td>
							<td style="border-top:1px solid #BBB;font-family: 微软雅黑; font-size: 33px;margin-top: 10px;">${bxPk}</td>
     	 					<td style="border-top:1px solid #BBB;"><button style="font-size: 20px;height: 30px;width: 120px;">日常报销</button></td>
     	 					<td colspan="3" style="border-top:1px solid #BBB;"><span style="margin-left: 80%;font-size: 30px;">${Amount}</span></td>
     	 	    </tr >
     	 	    <tr class="tr"> 
     	 	 
							<td style="border-bottom: 1px solid #BBB; font-family: '微软雅黑'; font-size: 30px; margin-bottom: 10px;">${fyCate}</td>
							<td colspan="4" style="border-bottom: 1px solid #BBB;"><span style="margin-left: 85%;font-size: 20px;"> ${fyday}</span></td>
     	 	    </tr >
     	 	    
     	 	    </table>
     	 	    </div>
  </body>
</html>

data: {startDat:"startDat",AuditStatus:"AuditStatus"},

应该是

data: {"startDat":startDat,"auditStatus":AuditStatus},

数据库是Mysql 字段类型是datetime、
前段的是input date 一直是数据类型不对

我曹 谢谢大牛 感谢感谢 是哪里的问题

你原本写的是字符串...

添加回复
请先登陆
回到顶部