Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

200
Views
SpringBoot RestController con @RequestParam y JQuery $.get()

Quiero hacer mi pequeño proyecto y crear una aplicación de biblioteca con API en Java y UI con ThymeLeaf y JQuery. Aquí está mi controlador

 @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); }

Aquí está mi interfaz de usuario en 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>

Quiero hacer una mesa con estos libros. ¡Pero cada mi llamada no hace nada! ¡Como si getJSON no viera mis parámetros de consulta en absoluto! También pruebo otras funciones, por ejemplo, simplemente get(/books-genre, {genre2 : drama}).done()...... nada cambia. Por favor, ayúdame a decirme qué hago mal... Porque otro controlador sin parámetros de consulta funciona bien

Es una captura de pantalla de mi solicitud a la que intento llamar.

ingrese la descripción de la imagen aquí

ingrese la descripción de la imagen aquí

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!