/AlumnosController.java Secret
Created
September 8, 2020 00:10
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package me.parzibyte.api; | |
import org.springframework.web.bind.annotation.*; | |
import org.springframework.beans.factory.annotation.Autowired; | |
@RestController | |
@RequestMapping(path = "/alumnos") | |
@CrossOrigin(origins = "http://localhost") | |
public class AlumnosController { | |
@Autowired | |
private AlumnosRepository alumnosRepository; | |
@RequestMapping(value = "/crear", method = RequestMethod.POST) | |
public Alumno crearAlumno(@RequestBody Alumno alumno) { | |
return alumnosRepository.save(alumno); | |
} | |
@RequestMapping(value = "/obtener", method = RequestMethod.GET) | |
public Iterable<Alumno> obtenerTodos() { | |
return alumnosRepository.findAll(); | |
} | |
@RequestMapping(value = "/eliminar/{id}", method = RequestMethod.DELETE) | |
public boolean eliminar(@PathVariable() Long id) { | |
alumnosRepository.deleteById(id); | |
return true; | |
} | |
@RequestMapping(value = "/actualizar", method = RequestMethod.PUT) | |
public Alumno editar(@RequestBody Alumno alumno) { | |
return alumnosRepository.save(alumno); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment