ajax调用返回 bad request 400 (日期格式)

处理JSON日期格式
本文介绍了一种处理前端向后台发送JSON格式数据时日期格式的方法,通过使用@JsonFormat注解指定日期格式为“yyyy-MM-dd HH:mm:ss”,确保了前后端交互中日期数据的正确解析。
function savePointBridge(){
var channelId = $("#channel_list :selected").val();
var pointId = parent.$("#paramId").val();
var bridge = {};
bridge.pointID = pointId;
bridge.chanID = channelId;
bridge.enabled =  $("#chkboxEnabled").is(':checked')?1:0;
bridge.sourceChanID =  $("#pntid_channel").val(); 
bridge.sourceDateStart =$("#starttime_point").val();
    bridge.sourceDateEnd = $("#endtime_point").val();
    bridge.autoModel=1;
$.ajax({
url:"../../channel/bridge",
data:JSON.stringify(bridge),
contentType:"application/json",
type:"POST",
success:function(data){
//alert(data.msg);
dialogAlert("系统提示",data.msg);
},
dataType:"json"
});
}

因为传输的格式不对,ajax传输json对日期格式有很高的要求,需要在模型层对日期格式进行处理,便于json识别

private Date sourceDateStart; private Date sourceDateEnd;

@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00") public Date getSourceDateStart() { return sourceDateStart; } @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00") public void setSourceDateStart(Date sourceDateStart) { this.sourceDateStart = sourceDateStart; } @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00") public Date getSourceDateEnd() { return sourceDateEnd; } @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00") public void setSourceDateEnd(Date sourceDateEnd) { this.sourceDateEnd = sourceDateEnd; }



http://blog.youkuaiyun.com/chenleixing/article/details/43740759从这里学会的,感谢分享~
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值