Difficulty to list data in a Spring Boot table

Asked

Viewed 756 times

1

I am working with a simple Spring Boot project using Thymeleaf, it is a product registration, as I have several types of products to register I found it interesting to create an entity called product and the other entities that was a type of product extend the product entity, ie, would create a class product and then create a class called the pipe and he would extend product, because the pipe is a type of product, as you can see below;

Product

@Entity
@Table(name = "produto")
public class Produto {

Pipe

@Entity
@Table(name = "cano")
public class Cano extends Produto implements Serializable{

Example;

The product needs to have the attributes that any product has to have, such as name, description and value, so it would create a class called Cano and would only put in that entity unique attributes of that entity and would inherit the attributes of the product class as name, description and value

In the act of saving it all worked out, as you can see below;

Controller class;

https://github.com/wladyband/arm/blob/master/arm/src/main/java/br/com/arm/controller/HidraulicoController.java

Page to register Cano

https://github.com/wladyband/arm/blob/master/arm/src/main/resources/templates/hidraulico/CadastroCano.html

I’m now trying to create a pipe search page, and I’m not being able to list database information in an HTML table. Although I have saved as a pipe, the pipe is a type of product, at the time of applying a select in the bank I have to make a select in the product table and not in the pipe table, the application does not even create the pipe table, because the pipe is a type of product, until there it is all right.

I’m cramming everything because it’s the first time I’m applying inheritance to my classes in my project.

See my Cano survey page;

<div class="table-responsive  bw-tabela-simples">
            <table class="table  table-hover">
                <thead>
                    <tr>
                        <th class="table-cervejas-col-foto"></th>
                        <th class="table-cervejas-col-nome">Nome</th>
                        <th class="table-cervejas-col-nome">Descrição</th>
                        <th class="table-cervejas-col-valor">Valor</th>
                        <th class="table-cervejas-col-acoes"></th>
                    </tr>
                </thead>

                <tbody>
                    <tr th:each="cano : ${canos}">
<!--                        <td class="text-center"> -->
<!--                            <img th:src="@{/fotos/temp/{foto}(foto=${cerveja.foto})}" class="img-responsive"/> -->
<!--                        </td> -->
                        <td class="text-center" th:text="${cano.nome}">AA1234</td>
                        <td th:text="${cano.descricao}">Cervej</td>
                        <td class="text-right" th:text="|R$ ${cano.valor}|">R$ 8.00</td>
                        <td class="text-center">
                            <a class="btn  btn-link  btn-xs" title="Editar"> 
                                <i class="glyphicon glyphicon-pencil"></i>
                            </a>
                            <a class="btn  btn-link  btn-xs" title="Excluir">
                                <i class="glyphicon glyphicon-remove"></i>
                            </a>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>

And insert this line of code into the controller;

@GetMapping
    public ModelAndView pesquisar(){
        ModelAndView mv = new ModelAndView("hidraulico/PesquisaHidraulicos");
        mv.addObject("canos", canos.findAll());
        System.out.println("valor dos canos >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + canos.findAll() );
        return mv;
    }

When I run the page the consoles presents me nothing returns nothing, someone could tell me how I will instantiate the values that are in the database for me to view in the HTML table?

  • The url for your "search" method was not missing: @Getmapping("/pipes/search")?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.