我必须将保护数据从数据库填充到通用复选框,并插入选定的复选框以存储在数据库中
public class ConservTabPageController {
@FXML
private FlowPane parent;
private ObservableList<CheckBox> checkBoxes = FXCollections.observableArrayList();
private ObservableList<Conservation> conservations;
public void setSelectedConserv(Species species) {
conservations = ConservationDAO.getConservations();
ObservableList<Conservation> conservationsBySpecies = SpeciesConservationDAO.getConservationsBySpecies(species);
conservations.forEach(conserv -> {
CheckBox checkBox = new CheckBox(conserv.getConservation());
int i = 0;
boolean found = false;
while (i < conservationsBySpecies.size() && !found) {
Conservation temp = conservationsBySpecies.get(i);
if (temp.getId() == conserv.getId()) {
found = true;
checkBox.setSelected(true);
}
i++;
}
checkBoxes.add(checkBox);
});
parent.getChildren().setAll(checkBoxes);
}
public ObservableList<Conservation> getIdSelectedCheckBoxes() {
ObservableList<Conservation> integers = FXCollections.observableArrayList();
FilteredList<CheckBox> filteredCheck = checkBoxes.filtered(CheckBox::isSelected);
conservations.forEach(conservation -> {
int i = 0;
boolean found = false;
while (i < filteredCheck.size() && !found) {
CheckBox checkBox = filteredCheck.get(i);
if (checkBox.getText().equals(conservation.getConservation())) {
found = true;
integers.add(conservation);
}
i++;
}
});
return integers;
}
}
setSelectedConserv (Species species)
检索保护表中的所有保留,并在父级中按名称填充它们,并验证哪些保留编号存储在especie_conservacion中以选择填充的复选框。
getIdSelectedCheckBoxes ()
按名称获取选中的复选框,并创建一个“保护列表”,以稍后将其保存到especie_conservacion表中。
我的问题是:
是否可以更改 setSelectedConserv (Species species)
和 getIdSelectedCheckBoxes ()
的内容以使用流api?还是有更好的选择?对不起,我的英语水平
这是表保护
|id_conservacion| nombre_conservacion |desc|
| 1 |Extinto |null|
| 2 |Críticamente amenazado|null|
| 3 |En peligro |null|
| 4 |Vulnerable |null|
| 5 |Cercano a la amenaza |null|
还有especie_conservacion
|id_especie|id_conservacion|
| 28 | 3 |
| 28 | 4 |