Spring Boot filled list has no values returned on the screen

0

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

@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 however in the front end the values are not returned to the "list".

<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/>
    
asked by anonymous 28.02.2018 / 18:19

1 answer

1

I think your problem is in redirect. Try using ModelAndView.

@GetMapping
public ModelAndView pesquisar(ParametroFiltro filtro){

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

    return mv;
}

In 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>    
    
07.03.2018 / 20:55