Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

204
Visualizações
SpringBoot RestController with @RequestParam and JQuery $.get()

I want to make my little project and build Library app with API on Java and UI with ThymeLeaf and JQuery. Here is my controller

@GetMapping(value = "/books-genre")
    public List<BookDto> findBooksByGenre(@RequestParam(name = "genre2") String genre) {
        System.err.println(genre);
        List<Book> books = BookService.findBooksByGenre(genre);
        return bookDtoConverter.booksToDto(books);
    }

Here is my UI in AJAx.

<script>
    function findBooksByGenre () {
        var x = document.getElementById("genre").value;
        console.log(x);
        var param = $.param(genre, x);
        var param2 = {
          genre : x
        };
        $.getJSON('/books-genre/' + $('#genre2').val()).done(function (books2) {
            alert(books2.length);
            books2.forEach(function (book2) {
                coment = book2.comments.length;
                cond = coment != 0 ? coment : 'no comments';
                $('tbody').append(`
                    <tr>
                        <td>${book2.id}</td>
                        <td>${book2.name}</td>
                        <td>${book2.author.name}</td>
                        <td>${book2.genre.name}</td>
                        <td> ${cond}
                        <a href="comments/?bookId=${book2.id}">view</a>
                        </td>
                    </tr>
                `)
            });
        })
    };
</script>


<div class="a">
    <h2>Options</h2>
    <form action="">
        <label for="genre">Choose by genre: </label>
        <input type="text" id="genre"/>
        <input type="submit" onclick="findBooksByGenre()" value="Submit"><br><br>
    </form>
</div>

I want to make a table with this books. But every my call do nothing! As if getJSON does not see my query params at all! I try another functions too, for example just get(/books-genre, {genre2 : drama}).done()...... nothing change. Please Help me say me what I do wrong.... Because another controller without query params works good

It is a screenshot of my request which i try to call

enter image description here

enter image description here

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda