- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个带有方法的 Controller :
@RequestMapping(value = "/request", method = RequestMethod.POST)
public Response<Boolean> requestAppt(
@RequestBody @Valid ApptRequest request
) {
System.out.println(request);
return Response.success(true);
}
我的 ApptRequest 是:
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.time.OffsetDateTime;
public class ApptRequest implements Serializable{
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
private OffsetDateTime date;
public ApptRequest() {
}
public OffsetDateTime getDate() {
return date;
}
public void setDate(OffsetDateTime date) {
this.date = date;
}
}
当我尝试发送带有请求正文的请求时:
{
"date": "2016-05-11T13:30:38+02:00"
}
我有一个异常(exception):
org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Can not instantiate value of type [simple type, class java.time.OffsetDateTime] from String value ('2016-05-11T13:30:38+02:00'); no single-String constructor/factory method
它表示OffsetDateTime 应该有一个只有一个字符串参数的构造函数或工厂方法。但我发现它需要带有 CharSequence 参数的工厂方法:
/**
* Obtains an instance of {@code OffsetDateTime} from a text string
* such as {@code 2007-12-03T10:15:30+01:00}.
* <p>
* The string must represent a valid date-time and is parsed using
* {@link java.time.format.DateTimeFormatter#ISO_OFFSET_DATE_TIME}.
*
* @param text the text to parse such as "2007-12-03T10:15:30+01:00", not null
* @return the parsed offset date-time, not null
* @throws DateTimeParseException if the text cannot be parsed
*/
public static OffsetDateTime parse(CharSequence text) {
return parse(text, DateTimeFormatter.ISO_OFFSET_DATE_TIME);
}
如果我尝试使用日期作为请求参数而不是请求正文属性,一切都会正常工作:
@RequestMapping(value = "/request", method = RequestMethod.POST)
public Response<Boolean> requestAppt(
@RequestParam @Valid @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) OffsetDateTime date
) {
System.out.println(date);
return Response.success(true);
}
也许我应该使用一些注释或类似的东西手动指定适当的构造函数?
最佳答案
将 datatype:jackson-datatype-jsr310 添加到类路径应该会有所帮助。灵感来自JSON Java 8 LocalDateTime format in Spring Boot
关于java - 如何在 Rest 请求体内使用带有单字符序列构造函数/工厂方法的对象而不是单字符串构造函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37993532/
因此,我的flutter应用程序运行正常,但是我想对其进行一些更改。 我要执行的第一个更改是创建一个水平滚动窗口小部件,该窗口小部件的图像可以单击以更改工作站。 但是要做到这一点,我首先需要将两个小部
如何在 Bootstrap 模态的主体内设置 div 样式?这是我的模型: text ') .okBtn('ok') .open();">Open Model 我的CSS: @M
我有一个简单的触发器,它在 SQL Fiddle 上运行,但它不允许我将 INSERT STATEMENT 移动到触发器的主体内。 my code on sqlFiddle我只是想移动这条线 INSE
我是一名优秀的程序员,十分优秀!