Oracle database data in combo box

Asked

Viewed 16 times

-1

In a Java project, I am using Hibernete, and Java Sprint Boot, the combo box was created in the registration screen, where the registration of a person is made, where a combo box is presented, with the courses registered in the table courses in the database, I created the functions, and made the necessary changes, as they can below, however it is presented the error below.

Object model

@Entity
@Table(name = "Curso")
public class Curso {

    @Id
    private int id_curso;
    private String des_curso;

    public Curso(int id_curso, String des_curso) {
        super();
        this.id_curso = id_curso;
        this.des_curso = des_curso;
    }
    
    public Curso() {
        
    }

    public int getId_curso() {
        return id_curso;
    }
    public void setId_curso(int id_curso) {
        this.id_curso = id_curso;
    }
    public String getDes_curso() {
        return des_curso;
    }
    public void setDes_curso(String des_curso) {
        this.des_curso = des_curso;
    }

}

Controler

@Controller
public class CursoController {

    @Autowired
    private CursoDao cursoDao;

    @RequestMapping("/cadastro")
    public ModelAndView getCurso() {
        
        ModelAndView mv = new ModelAndView("cadastro");
        Iterable<Curso> curso = cursoDao.findAll();
        mv.addObject("curso", curso);
        return mv;
    }
}

Dao

@Repository
@Transactional
public interface CursoDao extends JpaRepository<Curso, Integer> {

    public Curso getCursoById(int id);

}

HTML

<!DOCTYPE html>
<html xmlns:th="http://thymeleaf.org"
    xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
<title>Cadastrar-se</title>
<meta charset="UTF-8" />
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="/css/style.css" />
<script type="text/javascript" src="/js/style.css"> </script>
</head>
<body>
    <header>
    </header>
    <div align="center">
        </br></br> </br></br>
        <h3 align="center">Por favor, insira seus dados</h3>
        </br>
        <div align="center" >
            <form method="post" action="salvarpessoa" th:object="${pessoa}">
                <input type="text" name="nome" placeholder="Nome completo" />
                </br></br>
                <input type="text" name="login" placeholder="Login de acesso" />
                </br></br>
                <input type="password" name="senha" placeholder="Senha" />
                </br></br>
                <input type="number" name="periodo" placeholder="Período Ex: 1" />
                </br></br>
                <select name="id_cursos">
                                <select name="id_cursos">
                    <option>Escolha seu curso</option>
                    <option th:each="curso : ${curso}" 
                            th:value="${curso.id}"
                            th:text="${des_curso}">
                </option>
                </select>   <option>Escolha seu curso</option>
                    <option th:each="curso : ${curso}" 
                            th:value="${curso.id}"
                            th:text="${des_curso}">
                </option>
                </select>
                </br></br>
                <th:block th:include="mensagemValidacao"></th:block>
                </div>
                </br>
                <input type="submit" value="Concluir cadastro" name="action" class="btn btn-light"/>
                </br></br>  
                </form>
                <form action="/">
                    </br></br></br>
                    <input type="submit" value="Voltar" name="action" class="btn btn-light"/>
                </form>
        </div>
    </div>
</body>
</html>

Entity in a database

CREATE TABLE CURSO (
id_curso  NUMERIC(10),
desc_curso VARCHAR2(50),
PRIMARy key (id_disciplina));

Error

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cursoDao' defined in opet.edu.br.opet.models.Interfaces.CursoDao defined in @EnableJpaRepositories declared on OpetAppApplication: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract opet.edu.br.opetApp.models.Curso opet.edu.br.opet.models.Interfaces.CursoDao.getCursoById(int)! No Property id found for type Course! Caused by: java.lang.IllegalArgumentException: Failed to create query for method public abstract opet.edu.br.opetApp.models.Curso opet.edu.br.opet.models.Interfaces.CursoDao.getCursoById(int)! No Property id found for type Course!

1 answer

0

Try trading in your html
th:value="${course.id}" for th:value="${course.id_course}"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.