0
I am trying to pass data to test the front, but the controller is not getting the data that Spring Boot should start.
My application.properties:
spring.jpa.hibernate.ddl-auto=create
My import.sql:
INSERT INTO convidado
(id, nome, quantidadeDeAcompanhante)
VALUES(1, 'Pedro', 2);
INSERT INTO convidado
(id, nome, quantidadeDeAcompanhante)
VALUES(2, 'Ana', 5);
INSERT INTO convidado
(id, nome, quantidadeDeAcompanhante)
VALUES(3, 'Ricardo', 1);
My controller:
@Controller
public class ConvidadosController {
@Autowired
private Convidados convidados;
@GetMapping("/convidados")
public ModelAndView listar() {
ModelAndView modelAndView = new ModelAndView("ListaConvidados");
modelAndView.addObject("convidados", convidados.findAll());
System.out.println("***** " + convidados.findAll().toString() + " *******");
return modelAndView;
}
}
My Invited Entity:
@Entity
public class Convidado implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
private Long id;
private String nome;
private Integer quantidadeDeAcompanhante;
My Pository:
import com.gestaofestas.model.Convidado;
public interface Convidados extends JpaRepository<Convidado, Long> {
}
My folders:
In case it is returning an empty array and does not give error. How do I test this way by inserting data into the sql file that Spring Boot loads in Hibernate?
in fact the name that it will map to make this Insert is the "data.sql" no import.sql, check section 10.3 of the manual: https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto-database-initialization
– Lucas Miranda