我有3个TextFiled,一个将String保存到数据库,2个应该将FLoat保存到数据库。 当我运行我的应用程序时,我有这个错误:
Property type 'java.lang.Float' doesn't match the field type 'java.lang.String'. Binding should be configured manually using converter.
这是我的代码:
@SpringComponent
@UIScope
public class FuelEditor extends VerticalLayout{
private final FuelReposiotry fuelRepository;
private Fuel fuel;
/* Fields to edit properties in Customer entity */
TextField date = new TextField("Data");
TextField price = new TextField("Cena");
TextField amount = new TextField("Kwota tankowania");
/* Action buttons */
Button save = new Button("Save", FontAwesome.SAVE);
Button cancel = new Button("Cancel");
Button delete = new Button("Delete", FontAwesome.TRASH_O);
CssLayout actions = new CssLayout(save, cancel, delete);
Binder<Fuel> binder = new Binder<>(Fuel.class);
@Autowired
public FuelEditor(FuelReposiotry fuelReposiotry) {
this.fuelRepository = fuelReposiotry;
addComponents(date, price, amount, actions);
// bind using naming convention
binder.bindInstanceFields(this);
// Configure and style components
setSpacing(true);
actions.setStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
save.setStyleName(ValoTheme.BUTTON_PRIMARY);
save.setClickShortcut(ShortcutAction.KeyCode.ENTER);
// wire action buttons to save, delete and reset
save.addClickListener(e -> fuelReposiotry.save(fuel));
delete.addClickListener(e -> fuelReposiotry.delete(fuel));
cancel.addClickListener(e -> editFuel(fuel));
setVisible(false);
}
如何将String转换为Float?我尝试使用import com.vaadin.data.util.converter.StringToIntegerConverter;,但在vaadin 8中我无法使用转换器。
答案 0 :(得分:3)
您应该能够使用NSTimeZone *timeZone = [NSTimeZone defaultTimeZone];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeZone:timeZone];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"];
,但必须手动绑定这些字段:
StringToFloatConverter