Spring Boot filled list has no values returned on the screen

Asked

Viewed 205 times

0

The following method in my Controller is responsible for returning all values from a database table.

@RequestMapping("pesquisaTaxa")
public String pesquisaTaxa(@RequestParam Map<String, String> requestParams, HttpSession session, Model model) {

        String sigla = requestParams.get("siglaValue");
        String valorTxa = requestParams.get("valorTaxa");

        this.sigla= sigla;
        this.valor=valorTxa;


        //List<Taxasap> listaSap = taxaDao.getAllTaxasap(); //funcionando       
        List<Taxasap> listaSap = (List<Taxasap>) taxaSapRepository.findAll(); 

    if (sigla.equals("") && valorTxa.equals("")) {

        for (Taxasap taxaSAP : listaSap) {
            System.out.println("Sigla taxa: " + taxaSAP.getSigla() + " | Valor taxa: " + taxaSAP.getTaxa());

        }

        model.addAttribute("resulTaxas",listaSap);

    }

    return "redirect:/CadastroSAP?table";
}

The list is filled correctly with values but in front-end the values are not returned to the "listSap".

<div th:if="${param.table}">
        <table id="data" class="table table-hover table-bordered  table-responsive tableCenter">
            <thead>
                <tr>
                    <th>Sigla</th>
                    <th>Taxa</th>

                </tr>
            </thead>
            <tr th:each="txa : ${resulTaxas}">
                <td th:text="${txa.sigla}"></td>
                <td th:text="${txa.taxa}"></td>

            </tr>

        </table><br/><br/>
    </div><br/>

1 answer

1


I think your problem is in redirect. Try to use Modelandview.

@GetMapping
public ModelAndView pesquisar(ParametroFiltro filtro){

    ModelAndView mv = new ModelAndView("url");
    mv.addObject("lista",<sua lista>);

    return mv;
}

no Thymeleaf recover with ${list} Example(with bootstrap).

<table class="table table-hover">
    <thead>
        <tr>
            <th></th>
        </tr>
    </thead>
    <tbody>
        <tr th:each="item : ${lista}">
            <td></td>
        </tr>
    </tbody>
</tabel>    

Browser other questions tagged

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