Estoy tratando de devolver los datos de la base de datos, pero se ha producido este error. No sé que el error es 404 este es mi código: http: // localhost: 8085 / Ejercicios

mi clase de ejercicios


import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name = "exercice")
public class exercices implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long idExercice;

    private String nomExercice;
    private String LinkExercice;
    @ManyToOne
    private patient patient;

    public exercices(Long idExercice, String nomExercice, String linkExercice) {
        this.idExercice = idExercice;
        this.nomExercice = nomExercice;
        this.LinkExercice = linkExercice;
        this.patient = new patient();
    }

    public exercices(String nomExercice, String linkExercice) {
        this.nomExercice = nomExercice;
        LinkExercice = linkExercice;
    }

    public Long getIdExercice() {
        return idExercice;
    }

    public void setIdExercice(Long idExercice) {
        this.idExercice = idExercice;
    }

    public String getNomExercice() {
        return nomExercice;
    }

    public void setNomExercice(String nomExercice) {
        this.nomExercice = nomExercice;
    }

    public String getLinkExercice() {
        return LinkExercice;
    }

    public void setLinkExercice(String linkExercice) {
        LinkExercice = linkExercice;
    }

    @Override
    public String toString() {
        return "exercices [LinkExercice=" + LinkExercice + ", idExercice=" + idExercice + ", nomExercice=" + nomExercice
                + "]";
    }

}

EjercicioControlador


import java.util.List;

import org.apache.catalina.connector.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import healthP.Health.Progress.model.exercices;
import healthP.Health.Progress.service.ExerciceService;

@RestController
@RequestMapping()
public class ExerciceController {
    @Autowired
    private final ExerciceService exserv;

    public ExerciceController(ExerciceService exserv) {
        this.exserv = exserv;
    }

    @GetMapping("/exercices")
    public ResponseEntity<List<exercices>> getAllExercices() {
        List<exercices> ex = this.exserv.findAllExercices();
        return new ResponseEntity<>(ex, HttpStatus.OK);

    }

}

Ejerciceservice


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import healthP.Health.Progress.model.exercices;
import healthP.Health.Progress.repo.ExercicesRepo;

@Service
public class ExerciceService {
    private final ExercicesRepo ExRepo;

    @Autowired
    public ExerciceService(ExercicesRepo ExRepo) {
        this.ExRepo = ExRepo;
    }

    public List<exercices> findAllExercices() {
        return this.ExRepo.findAll();
    }

}

interfaz


import org.springframework.data.jpa.repository.JpaRepository;

import healthP.Health.Progress.model.exercices;

public interface ExercicesRepo extends JpaRepository<exercices, Long> {

}

Y esta es la clase de pacientes porque también quiero verificar si la relación entre dos clases es correcta y espacialmente en la construcción de la Clase de Ejercicio.

package healthP.Health.Progress.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;

import javax.persistence.Table;
//import org.hibernate.annotations.Table;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;

@Entity
@Table(name = "patient")
// @Table(name = patient.TABLE_NAME)
public class patient implements Serializable {
    // public static final String TABLE_NAME="PATIENT";
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int score;
    @Column(nullable = false, updatable = false)
    private Long id;
    private String name;
    private String email;
    private String password;
    @Column(nullable = false, updatable = false)
    private String codePatient;

    public patient() {
    }

    public patient(String codep, String name, String email, String password) {
        this.codePatient = codep;
        this.name = name;
        this.email = email;
        this.password = password;
    }

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return this.email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return this.password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getCodePatient() {
        return this.codePatient;
    }

    public void setCodePatient(String codePatient) {
        this.codePatient = codePatient;
    }

    public void setScore(int score) {
        this.score = score;
    }

    public int getScore() {
        return this.score;
    }

    @Override
    public String toString() {
        return "{" + " id='" + getId() + "'" + ", name='" + getName() + "'" + ", email='" + getEmail() + "'"
                + ", password='" + getPassword() + "'" + "}";
    }
}```
-1
Takwa 29 may. 2021 a las 03:27

2 respuestas

La mejor respuesta

Agregue API-RAYA a SOLICITUD DE PAZO DE EJERCICIOTRURRURLER, DESE

@RequestMapping("/api")
public class ExerciceController {

EDITAR:

Necesitas agregar constructor predeterminado a la entidad de ejercicios

public exercices(){}

Ahora puedes acceder a ella como http://localhost:8085/api/exercices

PD: No está relacionado con la pregunta, use el nombre de la clase singular para la entidad excercise en lugar de excercises

0
sanjeevRm 29 may. 2021 a las 09:18

Puede hacer pequeños cambios en su código y seguir cualquiera de los siguientes enfoques:

1- Eliminar @RequestMapping ()

Puede acceder a Endpoint: http: // localhost: 8085 / Ejercicios

2- Si desea administrar el versionamiento de la API, use @RequestMapping ("/ API / V1")

Puede usar el punto final: http: // localhost: 8085 / API / V1 / Ejercices

0
Gaurav Shakya 29 may. 2021 a las 02:49