js 中用$('#addUserForm').serialize(),//获取表单中所有数据 传送到前台 (controller) $.ajax({ type : "POST", url : $.el.Register.AppUrl + "path", data :$('#addUserForm').serialize(),//获取表单中所有数据 dataType : 'json', async : false, success : function(msg) { }, error : function(error) { } }); 这时如果表单中有时间类型 因为传过来的都是字符串类型 所以前台(实体)的时间类型接不到 解决方法: (1)可在entity 实体里字段上加@DateTimeFormat(pattern = "yyyy-MM-dd") (2) 在controller中用个String接这个变量(不能和字段名重名) 转化为时间类型 再用 就可以了 public String addTask(User user(实体对象),String dateStr(用于接时间)) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); ParsePosition pos = new ParsePosition(0); Date date = sdf.parse(dateStr,pos); gzrw.setEndtime(date);//将时间加入实体 }  前两种方法如果不好用 或者关联到其他方法不能使用  就将时间字段进行处理 cdtimev.ToDate()   cdtimev是你在js里获取的时间 ToDate()  可以转化为时间类型  在conroller里就可以接到了(js获取的所有值都是String类型)

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-04
  • 2021-03-31
  • 2021-11-30
  • 2021-04-25
  • 2022-12-23
  • 2021-06-05
猜你喜欢
  • 2022-12-23
  • 2021-09-19
  • 2022-12-23
  • 2022-12-23
  • 2022-01-11
  • 2022-12-23
相关资源
相似解决方案