Java 同一列中有两种不同类型的值
这张表有一列,我在其中显示了一个数量。例如,我想显示数量和计量单位Java 同一列中有两种不同类型的值,java,javafx,Java,Javafx,这张表有一列,我在其中显示了一个数量。例如,我想显示数量和计量单位 60 meters 10 pieces 20 liters (the first column) 这是我在表中显示的对象: 公共级VentaDetalle{ private IntegerProperty idVentaDetalle; private IntegerProperty idMercancia; private StringProperty nombreMercancia; private IntegerProp
60 meters
10 pieces
20 liters
(the first column)
这是我在表中显示的对象:
公共级VentaDetalle{
private IntegerProperty idVentaDetalle;
private IntegerProperty idMercancia;
private StringProperty nombreMercancia;
private IntegerProperty idVentaGeneral;
private DoubleProperty cantidad;
private DoubleProperty general;
private DoubleProperty mayoreo;
private DoubleProperty subtotal;
public VentaDetalle(int idMercancia, String nombreMercancia, int idVentaGeneral,
Double cantidad, double mayoreo, double general, Double subtotal) {
this.idMercancia = new SimpleIntegerProperty(idMercancia);
this.nombreMercancia = new SimpleStringProperty(nombreMercancia);
this.idVentaGeneral = new SimpleIntegerProperty(idVentaGeneral);
this.cantidad = new SimpleDoubleProperty(cantidad);
this.mayoreo = new SimpleDoubleProperty(mayoreo);
this.general = new SimpleDoubleProperty(general);
this.subtotal = new SimpleDoubleProperty(subtotal);
}
//Metodos atributo: idVentaDetalle
public int getIdVentaDetalle() {
return idVentaDetalle.get();
}
public void setIdVentaDetalle(int idVentaDetalle) {
this.idVentaDetalle = new SimpleIntegerProperty(idVentaDetalle);
}
public IntegerProperty IdVentaDetalleProperty() {
return idVentaDetalle;
}
//Metodos atributo: idMercancia
public int getIdMercancia() {
return idMercancia.get();
}
public void setIdMercancia(int idMercancia) {
this.idMercancia = new SimpleIntegerProperty(idMercancia);
}
public IntegerProperty IdMercanciaProperty() {
return idMercancia;
}
//Metodos atributo: nombreMercancia
public String getNombreMercancia() {
return nombreMercancia.get();
}
public void setNombreMercancia(String nombreMercancia) {
this.nombreMercancia = new SimpleStringProperty(nombreMercancia);
}
public StringProperty NombreMercanciaProperty() {
return nombreMercancia;
}
//Metodos atributo: idVentaGeneral
public int getIdVentaGeneral() {
return idVentaGeneral.get();
}
public void setIdVentaGeneral(int idVentaGeneral) {
this.idVentaGeneral = new SimpleIntegerProperty(idVentaGeneral);
}
public IntegerProperty IdVentaGeneralProperty() {
return idVentaGeneral;
}
//Metodos atributo: cantidad
public Double getCantidad() {
return cantidad.get();
}
public void setCantidad(Double cantidad) {
this.cantidad = new SimpleDoubleProperty(cantidad);
}
public DoubleProperty CantidadProperty() {
return cantidad;
}
//Metodos atributo: general
public Double getMayoreo() {
return mayoreo.get();
}
public void setMayoreo(Double mayoreo) {
this.mayoreo = new SimpleDoubleProperty(mayoreo);
}
public DoubleProperty MayoreoProperty() {
return mayoreo;
}
//Metodos atributo: general
public Double getGeneral() {
return general.get();
}
public void setGeneral(Double general) {
this.general = new SimpleDoubleProperty(general);
}
public DoubleProperty GeneralProperty() {
return general;
}
//Metodos atributo: subtotal
public Double getSubtotal() {
return subtotal.get();
}
public void setSubtotal(Double subtotal) {
this.subtotal = new SimpleDoubleProperty(subtotal);
}
public DoubleProperty SubtotalProperty() {
return subtotal;
我对列进行如下初始化:
clmnCantidad.setCellValueFactory(new PropertyValueFactory<VentaDetalle, Double>("cantidad"));
clmnCantidad.setCellValueFactory(新属性值工厂(“cantidad”);
我从带有表项的数据库中获取单元
这个表有name、stock、codebar和unitofmeasuremen我不打算回答SQL查询中的部分-理想情况下,它应该是某种结合这两个表的
JOIN
语句
在组合IntegerProperty
和StringProperty
时,有两种主要方法
方法1:创建一个新属性,将它们连接到模型类中
然后您只需要设置单元格值工厂:
clmnCantidad.setCellValueFactory(new PropertyValueFactory<>("cantidadWithUnit"));
提供一些代码,以便我们了解您的数据结构。您如何确定单位?我已经编辑了我的ask@jai,我将做一个猜测,因为这里有很多非英语的内容。我将假设“nombre”表示名称,此名称用于与数据库中的另一个表进行匹配,以找出条目使用的度量单位?是的,我正在使用我的数据库项和saleDetail的两个表,我想这样做:在
VentaDetalle
类中添加度量单位属性可能更整洁,并且当您通过在SQL中,您可以执行一个内部联接SQL查询,以同时获取数量和单位。然后您可以创建一个自定义单元格值工厂,将这两个属性串联起来。
clmnCantidad.setCellValueFactory(new PropertyValueFactory<>("cantidadWithUnit"));
clmnCantidad.setCellValueFactory(row ->
Bindings.concat(row.getValue().cantidadProperty(), " ", row.getValue().measurementUnitProperty())
);