胸腺循环在具有对象列表属性问题的对象列表上

发布于 2025-02-10 17:49:06 字数 2173 浏览 2 评论 0 原文

我正在春季靴子上工作,胸腺呈现不同的桌子的桌子呈现问题。首先必须是一个字符串,后续行必须是保存在对象列表中的数据。

问题的情况:

我有一个对象列表,此对象具有两个属性,一个是字符串列表,另一个是不同对象的列表。我不知道如何在表中的胸腺中渲染一行中字符串列表的第一个属性,以及该表的下一行呈现属性对象的第二个列表。

该对象的详细信息:

public class objetosDeServiciosAD {

    private String Servicio;
    private LinkedList<usuarioAD> listaUsuariosAD;

    public String getServicio() {
        return Servicio;
    }
    public void setServicio(String servicio) {
        Servicio = servicio;
    }
    public LinkedList<usuarioAD> getListaUsuariosAD() {
        return listaUsuariosAD;
    }
    public void setListaUsuariosAD(LinkedList<usuarioAD> listaUsuariosAD) {
        this.listaUsuariosAD = listaUsuariosAD;
    }
    @Override
    public String toString() {
        return "objetosDeServiciosAD [Servicio=" + Servicio + ", listaUsuariosAD=" + listaUsuariosAD + "]";
    }
        
}   

objetos_servicios是一个具有两个侵犯的对象的列表,一个是Servicio 该对象具有第二个Attibute,它是对象列表,这是Listausuariosad。

这是我在胸腺中的代码:

<table class="table table-hover">
    <thead class="thead-light">
        <tr>
            <th scope="col">Usuario</th>
            <th scope="col">Teléfono</th>
            <th scope="col">mail</th>
            <th scope="col">Descripción</th>
        </tr>
    </thead>
    <tbody>
        <tr th:each="servicio : ${objetos_Servicios}">
            <td th:text="${servicio.servicio}"></td>            
        <tr th:each=" listaeusuario : ${servicio.listaUsuariosAD}">
            <tr th:each ="usuarios : ${listaeusuario}">
                <td th:text = "${usuarios.usuario}"></td>
                <td th:text = "${usuarios.telefono}"></td>
                <td th:text = "${usuarios.mail}"></td>
                <td th:text = "${usuarios.descripion}"></td>
                  
            </tr>
        </tr>                            
    </tbody> 
      
</table>

I'm working in Spring Boot and I have a problem rendering with Thymeleaf a table with different lines. First must be a String, and the subsequent lines must be the data saved in a list of objects.

situation of the problem:

I have a list of objects, this object has two attributes, one is a list of Strings, and the other one is a list of different objects. I don't know how to render in Thymeleaf in a table the first attribute of a string list in a line, and on the next lines of the table render the second list of attribute object.

details of the object:

public class objetosDeServiciosAD {

    private String Servicio;
    private LinkedList<usuarioAD> listaUsuariosAD;

    public String getServicio() {
        return Servicio;
    }
    public void setServicio(String servicio) {
        Servicio = servicio;
    }
    public LinkedList<usuarioAD> getListaUsuariosAD() {
        return listaUsuariosAD;
    }
    public void setListaUsuariosAD(LinkedList<usuarioAD> listaUsuariosAD) {
        this.listaUsuariosAD = listaUsuariosAD;
    }
    @Override
    public String toString() {
        return "objetosDeServiciosAD [Servicio=" + Servicio + ", listaUsuariosAD=" + listaUsuariosAD + "]";
    }
        
}   

objetos_Servicios is a list of objects with two atributes, one is servicio
this object has a second attibute which is a list of objects, this is listaUsuariosAD.

This is my code in Thymeleaf:

<table class="table table-hover">
    <thead class="thead-light">
        <tr>
            <th scope="col">Usuario</th>
            <th scope="col">Teléfono</th>
            <th scope="col">mail</th>
            <th scope="col">Descripción</th>
        </tr>
    </thead>
    <tbody>
        <tr th:each="servicio : ${objetos_Servicios}">
            <td th:text="${servicio.servicio}"></td>            
        <tr th:each=" listaeusuario : ${servicio.listaUsuariosAD}">
            <tr th:each ="usuarios : ${listaeusuario}">
                <td th:text = "${usuarios.usuario}"></td>
                <td th:text = "${usuarios.telefono}"></td>
                <td th:text = "${usuarios.mail}"></td>
                <td th:text = "${usuarios.descripion}"></td>
                  
            </tr>
        </tr>                            
    </tbody> 
      
</table>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝颜夕 2025-02-17 17:49:06

该代码将看起来像这样:

<table class="table table-hover">
  <thead class="thead-light">
    <tr>
      <th scope="col">Usuario</th>
      <th scope="col">Teléfono</th>
      <th scope="col">mail</th>
      <th scope="col">Descripción</th>
    </tr>
  </thead>
  
  <tbody>
    <th:block th:each="servicio : ${objetos_Servicios}">
      <tr>
        <td th:text="${servicio.servicio}" />
      </tr>          
      
      <tr th:each = "lista : ${servicio.getListaUsuariosAD()}">
        <td th:text="${lista.usuario}"></td>
        <td th:text="${lista.telefono}"></td>
        <td th:text="${lista.mail}"></td>
        <td th:text="${lista.Descripcion}"></td>
      </tr>
    </th:block>
  </tbody> 
</table>

您可以使用 th:block 标签在较大的代码块上循环(其中包含标题&lt; tr/&gt; 和行&lt; tr /&gt; < /code>)。

The code will look something like this:

<table class="table table-hover">
  <thead class="thead-light">
    <tr>
      <th scope="col">Usuario</th>
      <th scope="col">Teléfono</th>
      <th scope="col">mail</th>
      <th scope="col">Descripción</th>
    </tr>
  </thead>
  
  <tbody>
    <th:block th:each="servicio : ${objetos_Servicios}">
      <tr>
        <td th:text="${servicio.servicio}" />
      </tr>          
      
      <tr th:each = "lista : ${servicio.getListaUsuariosAD()}">
        <td th:text="${lista.usuario}"></td>
        <td th:text="${lista.telefono}"></td>
        <td th:text="${lista.mail}"></td>
        <td th:text="${lista.Descripcion}"></td>
      </tr>
    </th:block>
  </tbody> 
</table>

You can use a th:block tag to loop over a larger block of code (that contains the header <tr /> and the rows <tr />).

眉黛浅 2025-02-17 17:49:06

我建议更改您正在使用的命名标准,以便所有类名称都以上案字母开头 - 例如: objetosdesviciosad 而不是 objetosdesviciosad 。这是Java中的标准配置 - 对于其他阅读您的代码的人来说,不这样做可能会使您感到困惑。

因此,您的类变为:

import java.util.List;

public class ObjetosDeServiciosAD {

    private String servicio;
    private List<UsuarioAD> listaUsuariosAD;

    public String getServicio() {
        return servicio;
    }

    public void setServicio(String servicio) {
        this.servicio = servicio;
    }

    public List<UsuarioAD> getListaUsuariosAD() {
        return listaUsuariosAD;
    }

    public void setListaUsuariosAD(List<UsuarioAD> listaUsuariosAD) {
        this.listaUsuariosAD = listaUsuariosAD;
    }

}

我还用 list 替换了 linkedlist ,因为您似乎在此处需要链接列表(如果您实际上这样做,则可以恢复更改) 。

然后,对于胸腺模板,您可以使用百里叶的 标记要构造迭代循环:

<table class="table table-hover">
    <thead class="thead-light">
        <tr>
            <th scope="col">Usuario</th>
            <th scope="col">Teléfono</th>
            <th scope="col">mail</th>
            <th scope="col">Descripción</th>
        </tr>
    </thead>

    <tbody>
        <th:block th:each="servicio : ${objetos_Servicios}">
            <tr>
                <td th:text="${servicio.servicio}" />
                <td></td>
                <td></td>
                <td></td>
            </tr>          

            <tr th:each = "lista : ${servicio.listaUsuariosAD}">
                <td th:text="${lista.usuario}"></td>
                <td th:text="${lista.telefono}"></td>
                <td th:text="${lista.mail}"></td>
                <td th:text="${lista.descripcion}"></td>
            </tr>
        </th:block>
    </tbody> 
</table>

在上面的代码中,我还替换了 $ {servicio.getListausuarioSad()} simpler $ {servicio.listausuariosad} ,由于您无需明确调用该方法,因此。

我还添加了三个空的&lt; td&gt;/td&gt; 单元格以确保每行完成,用于显示 servicio text的行。

I recommend changing the naming standards you are using, so that all your class names begin with an upper-case letter - for example: ObjetosDeServiciosAD instead of objetosDeServiciosAD. This is standard in Java - and not doing this can be confusing for other people who read your code.

So, your class becomes:

import java.util.List;

public class ObjetosDeServiciosAD {

    private String servicio;
    private List<UsuarioAD> listaUsuariosAD;

    public String getServicio() {
        return servicio;
    }

    public void setServicio(String servicio) {
        this.servicio = servicio;
    }

    public List<UsuarioAD> getListaUsuariosAD() {
        return listaUsuariosAD;
    }

    public void setListaUsuariosAD(List<UsuarioAD> listaUsuariosAD) {
        this.listaUsuariosAD = listaUsuariosAD;
    }

}

I also replaced LinkedList with List, since you do not appear to need a linked list here (if you actually do, you can revert that change).

Then, for your Thymeleaf template, you can use Thymeleaf's <th:block> tag to structure your iteration loops:

<table class="table table-hover">
    <thead class="thead-light">
        <tr>
            <th scope="col">Usuario</th>
            <th scope="col">Teléfono</th>
            <th scope="col">mail</th>
            <th scope="col">Descripción</th>
        </tr>
    </thead>

    <tbody>
        <th:block th:each="servicio : ${objetos_Servicios}">
            <tr>
                <td th:text="${servicio.servicio}" />
                <td></td>
                <td></td>
                <td></td>
            </tr>          

            <tr th:each = "lista : ${servicio.listaUsuariosAD}">
                <td th:text="${lista.usuario}"></td>
                <td th:text="${lista.telefono}"></td>
                <td th:text="${lista.mail}"></td>
                <td th:text="${lista.descripcion}"></td>
            </tr>
        </th:block>
    </tbody> 
</table>

In the above code, I also replaced ${servicio.getListaUsuariosAD()} with the simpler ${servicio.listaUsuariosAD}, since you do not need to explicitly call the method, here.

I also added three empty <td></td> cells to ensure each row is complete, for the row displaying the servicio text.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文