本文介绍了如何在Vaadin 8中输入时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 DateTimeField 输入时间戳,但是在我的实体中,我具有 java.sql.timestamp .将datetimefield转换为时间戳给出了错误
I am trying to enter timestamp using DateTimeField but in my entity i am having java.sql.timestamp. Converting datetimefield to timestamp is giving error
ConversionClass
ConversionClass
package com.vaadin.convertor;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import com.vaadin.data.Converter;
import com.vaadin.data.Result;
import com.vaadin.data.ValueContext;
@SuppressWarnings("serial")
public class StringTimestampConvertor implements Converter<LocalDateTime,
Timestamp> {
@SuppressWarnings("unchecked")
public Result<Timestamp> convertToModel(LocalDateTime value, ValueContext
context) {
Result<Timestamp> rs = (Result<Timestamp>) Timestamp.valueOf(value);
return rs;
}
@Override
public LocalDateTime convertToPresentation(Timestamp value, ValueContext
context) {
// TODO Auto-generated method stub
return null;
}
}
这给出了无法将时间戳转换为结果的错误
This is giving error that Timestamp cannot be casted into Result
推荐答案
这不是正确的转换方式(您不能将Timestamp
类转换为Result
)
This is not a correct way of casting (You cannot cast a Timestamp
class to a Result
)
您应该改为Result.ok(Timestamp.valueOf(value));
(结果界面 )
这篇关于如何在Vaadin 8中输入时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!