ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
前后端传递时间类型数据需要做如下处理: **1. 在时间类型的变量上标记注解`@DateTimeFormat`、`@JSONField`** ```java @Data public class Student { @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JSONField(format = "yyyy-MM-dd HH:mm:ss") private Date born; } ``` **2. controller层** ```java @Controller public class AsyncController { @ResponseBody @PostMapping(value = "/v2/async/student") public Student getMessage(Student student) { //Student(born=Thu Jun 02 20:14:30 CST 2022) System.out.println(student); return student; } } ``` **3. 前端传递时间** ```js $.ajax({ async: true, type: 'post', url: '${pageContext.request.contextPath}/v2/async/student', data: { 'born': '2022-06-02 20:14:30'}, dataType: 'json', beforeSend: function () { }, success: function (data) { console.log(data) //{born: '2022-06-02 20:14:30'} }, error: function (data) { } }) ```