🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
前后端传递时间类型数据需要做如下处理: **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) { } }) ```