1

spring tool me tira error al enviar una Lista de objetos. Funciona si envío un solo objeto, si envío una lista me tira este error:

Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback.

Tue Nov 03 18:24:30 ART 2020 There was an unexpected error (type=Internal Server Error, status=500). Exception evaluating SpringEL expression: "post.title" (template: "index" - line 47, col 21)

Muchas gracias!!

package com.floxy.core.controllers;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.floxy.core.model.Post;
import com.floxy.core.model.Prueba;



@Controller
@RequestMapping("/home")
public class ControllerBasic {      
    
    public List<Prueba> getPrueba() {
        Prueba prue1 = new Prueba(1,"descripcion", "img", "titulo");    
        Prueba prue2 = new Prueba(2,"descripcion2", "img2", "titulo2"); 
        
        List<Prueba> listaPruebas = new ArrayList<>();
        listaPruebas.add(prue1);
        listaPruebas.add(prue2);
            
        
        return listaPruebas;
    }
    
    
    @GetMapping(path = {"/post", "/"})
    public String saludar(Model model) {
        model.addAttribute("post", this.getPrueba());
        return "index";     
    }
    
}


        <!-- open card --> 
          <div th:each="post : ${posts}" class="col-3"/>             
            <div class="card" style="width: 18rem;">
              <img class="card-img-top" src="../static/img/img-flower.jpg" alt="Card image cap">
              <div class="card-body">
                <h5 th:text="${post.title}" class="card-title">adfasdf</h5>
                <p th:text="${post.description}" class="card-text"></p>
                <a href="#" class="btn btn-primary"></a>
              </div>
            </div>                          
          </div>
          <!-- close card -->









1
  • Agrega la clase Prueba, puede que el problema se encuentre allí. el 17 nov. 2023 a las 6:36

1 respuesta 1

1

El problema que tienes está en:

model.addAttribute("post", this.getPrueba());

Tal y como tienes en la vista post debería ser en plural:

model.addAttribute("posts", this.getPrueba());
2
  • Hola! lo cambié, pero me sigue tirando el mismo error Exception evaluating SpringEL expression: "post.title" (template: "index" - line 47, col 21)
    – aliprog
    el 3 nov. 2020 a las 22:53
  • ¿Cómo es la clase Prueba?
    – sergiomse
    el 4 nov. 2020 a las 7:36

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.