Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created September 8, 2020 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/76361f9212119b224a00fa9a6111b55d to your computer and use it in GitHub Desktop.
Save parzibyte/76361f9212119b224a00fa9a6111b55d to your computer and use it in GitHub Desktop.
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