@DELETE @Path("users/{id}") public void deleteUserById(@PathParam("id") Long id) { User user = getUserById(id); userDao.deleteUser(user); }
@POST @Path("users") public void createUser( @FormParam("fname") String fname, @FormParam("lname") String lname, @FormParam("id") Long id) { User user = new User(fname, lname, id); userDao.createUser(user); }
@GET @Path("users") // JSON: include "application/json" in the @Produces annotation to include json support @Produces({"application/json"}) // @Produces({ "application/xml" }) public Map<String, List<User>> getUsersMap() { Map<String, List<User>> result = new HashMap<String, List<User>>(); result.put("users", userDao.getAll()); return result; }
private User getUser(Long id) { for (User user : userDao.getAll()) if (user.getId().equals(id)) return user; throw new WebApplicationException(Response.Status.NOT_FOUND); }