Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.forge.miniproyecto.resource;
- import com.example.forge.miniproyecto.dao.UserDAO;
- import com.example.forge.miniproyecto.entity.User;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import java.util.List;
- @RestController
- @RequestMapping("user")
- public class UserResource {
- @Autowired
- UserDAO userDao;
- // crear (C de crud)
- @RequestMapping(method = RequestMethod.POST)
- public User crearUsuario(@RequestBody User usuario){
- int retorno = userDao.insertar(usuario);
- return usuario;
- }
- // recuperar
- @RequestMapping(method = RequestMethod.GET)
- public List<User> listarUsuarios(){
- return userDao.listarUsuarios();
- }
- // eliminar
- //@RequestMapping(method = RequestMethod.DELETE, value = "/{id}")
- @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
- public int eliminar(@PathVariable("id") int id){
- int retorno = userDao.eliminar(id);
- return retorno;
- }
- // actualizar
- @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
- public int actualizar(@RequestBody User usuario, @PathVariable("id") int id){
- int retorno = userDao.actualizar(usuario, id);
- return retorno;
- }
- // recuperar
- @RequestMapping(value = "/find/{id}", method = RequestMethod.GET)
- public User findId(@PathVariable("id") int id){
- return userDao.findId(id);
- }
- // Exist
- @RequestMapping(value = "/mail/{correo}", method = RequestMethod.GET)
- public boolean isExist (@PathVariable("correo") String correo){
- return userDao.isExists(correo);
- }
- }
Add Comment
Please, Sign In to add comment