如何在 Vaadin 8 中输入时间戳

2022-01-19 00:00:00 frontend sql-timestamp java vaadin8

我正在尝试使用 DateTimeField 输入 timestamp,但在我的实体中我有 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

转化类

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

推荐答案

这导致无法将时间戳转换为结果的错误

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)

结果<时间戳>rs = (Result) Timestamp.valueOf(value);

您应该改为 Result.ok(Timestamp.valueOf(value));( 结果接口)

相关文章