我正在制作一个网页抓取应用程序,所以我不使用任何数据库,只是使用javabean来存储数据和xhtml页面来显示它,现在我有一个arraylist对象,其中每个对象都有我需要在xhtml页面中显示的数据,但我不知道该怎么做。 我知道使用 jSTL 与 jsp 是可能的,但几天前我听说现在几乎没有人使用 jsp,...所以我不想在这个项目中使用它。
javabean
@ManagedBean(name = "login")
@SessionScoped
public class Login implements Serializable{
private boolean isLoged=false;
PortalUDB portaludb;
Estudiante estudiante; // This is the object tha has the array list
包含两个对象数组列表的类
public final class Estudiante{
private Document document;
private int uv_carrera;
private int uv_actuales;
private final Connection.Response loginForm;
public List<MateriaPensum> materia_pensum = new ArrayList<>();
public List<MateriaExpediente> materia_expediente = new ArrayList<>();
我已经使用 ui:repeat 实现了它
<ui:repeat var="materia" value="#{login.estudiante.materia_expediente}"> <h1>#{materia.asignatura}</h1> </ui:repeat>
只是我不知道为什么我可以使用 MateriaExpediente 类中的每个私有(private)变量。
public class MateriaExpediente extends MateriaPensum{
int anio;
String ciclo;
String asignatura;
String matricula;
float nota;
String resultado;
也许是因为我使用了 getter 和 setter 方法?
最佳答案
如果您使用的是 Spring MVC
或 Spring Boot
那么您可以使用 Thymeleaf 。我猜您正在将 Estudiante
bean 作为 estudiante
属性传递到请求范围。因此,为了循环 html 中的 materia_pensum
列表:
<p th:each="materiaPensum : ${estudiante}" th:text="${materiaPensum.name}"><p/>
关于java - 使用 javabean 显示 arraylist 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56334698/