submitForm(formName) {
this.$refs[formName].validate((valid) => {
let url = 'http://localhost:8088/pethospital/order-record'
let data = qs.stringify({
title: this.orderForm.title,
hospitalId: this.orderForm.hospitalId,
orderDate: this.orderForm.orderDate,
orderType: this.orderForm.orderType,
petVariety: this.orderForm.petVariety,
mobilePhone: this.orderForm.mobilePhone,
supplement: this.orderForm.supplement
})
if (valid) {
axios.post(url, data)
.then(response => {
}).catch(error => {
this.$message({
message: '错误:' + error,
type: true
})
})
} else {
this.$message('验证错误:请确认信息是否填写完整')
}
});
}
private Long id;
private String title;
private Integer hospitalId;
private Date orderDate;
private Integer orderType;
private String petVariety;
private String mobilePhone;
private String supplement;
@PostMapping("/order-record")
public CommonResult addOrderRecord(OrderRecordDO orderRecordDO) throws ParseException {
System.out.println("添加的预约记录:" + orderRecordDO);
orderRecordDOMapper.insertSelective(orderRecordDO);
return null;
}
Field error in object 'orderRecordDO' on field 'orderDate': rejected value [2019-04-10 10:00:00]; codes [typeMismatch.orderRecordDO.orderDate,typeMismatch.orderDate,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [orderRecordDO.orderDate,orderDate]; arguments []; default message [orderDate]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'orderDate'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.util.Date] for value '2019-04-10 10:00:00'; nested exception is java.lang.IllegalArgumentException]]
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date orderDate;
添加的预约记录:{"id":null,"title":"测试1","hospitalId":1001,"orderDate":"Wed Apr 10 10:00:00 CST 2019","orderType":2001,"petVariety":"哈士奇","mobilePhone":"1000","supplement":"二哈"}
/**
* timezone = "GMT+8"指定时区
*/
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date orderDate;
# 配置数据源
spring:
datasource:
name: pet-hospital
type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:mysql://localhost:3306/pet_hospital?serverTimezone=GMT%2B8
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: 1741248769
# Vue前端传来的日期为String类型,下面的设置可以自动将其转换为Date类型,不需要手动转换
mvc:
date-format: yyyy-MM-dd HH:mm:ss
# 以下设置可以将Date类型自动转换为如下格式的日期,指定Jackson格式化日期使用的时区,Jackson默认使用UTC
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
附:简书地址