Last active
August 29, 2015 14:19
-
-
Save kuflash/084dd83c6caa1afe1cc0 to your computer and use it in GitHub Desktop.
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
// DAO | |
public static void save(User user) throws PSQLException { | |
EntityManager em = AppEntityManager.getInstance(); | |
em.getTransaction().begin(); | |
em.persist(user); | |
em.getTransaction().commit(); | |
} | |
// Controller | |
public static Result add() { | |
User user = (User) Json.fromJson(request().body().asJson(), User.class); | |
try { | |
UserDAO.save(user); | |
} catch (PSQLException e) { | |
return badRequest(Json.toJson(e.getMessage())).as("application/json"); | |
} | |
return ok(Json.toJson(user)).as("application/json"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment