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

172
Views
Acceda a variables Set específicas de Spring usando Javascript

¿Cómo accedo a variables Set específicas de Spring usando Javascript?

Mi controlador devuelve un conjunto de datos que contiene la siguiente información de varias clases

 Person String firstName; String lastName; int age; Address String country; String city;

Que se pasa al html como model.addAttribute("personSet", form);

Cuando se pasa al html, los datos se vuelven así:

 Set1 (from Person Class) firstName = John lastName = Doe age = 20 (from Address Class) country = Japan city = Tokyo Set 2 (from Person Class) firstName = Mary lastName = Smith age = 30 (from Address Class) country = Korea city = Seoul

Lo que estoy tratando de hacer con javascript es que quiero obtener los datos variables específicos para poder realizar una condición if para cada elemento del conjunto. Por ejemplo: para cada persona en personSet, si país = Japón, escriba firstName + lastName.

Para solucionar esto creé el siguiente código

Tenga en cuenta que eliminé algunas declaraciones de variables y este es un fragmento de código js en línea que contiene el siguiente código:

 <script th:inline="javascript"> and /*<![CDATA[*/ function printPeopleFromJapan() { //get the data of the whole set personSetJS = /*[[${personSet.Person}]]*/'default'; //loop through all persons in the set for (person of personSet) { country = /*[[${personSet.country}]]*/'default'; //if country is equal to Japan, get the person full name if (country == "Japan") { personFirstName = /*[[${personSet.firstName}]]*/'default'; personLastName = /*[[${personSet.lastName}]]*/'default'; console.log(personFirstName + personLastName); } } }

Pero mi programa no se ejecuta y recibo errores y una página en blanco.

 Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "personSet.Person"

Por favor ayuda.

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!