Advertisement
Guest User

Untitled

a guest
Jan 19th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. POST /json @controllers.Application.saveJsonData
  2.  
  3. def saveJsonData = Action { request =>
  4. val body: AnyContext = request.body
  5. val jsonBody: Option[JsValue] = body.asJson
  6. jsonBody.map {json =>
  7. dao.persist(json) // stores in database, not found: dao
  8. Ok("Saved")
  9. }.getOrElse {
  10. BadRequest("Expecting text/json request.body")
  11. }
  12. }
  13.  
  14. db.default.driver=org.postgresql.Driver
  15. db.default.url="jdbc:postgresql://localhost:5432/database"
  16. db.default.user=test
  17. db.default.password=1234
  18.  
  19. val appDependencies = Seq(
  20. "org.postgresql" % "postgresql" % "9.4-1200-jdbc41",
  21. "postgresql" % "postgresql" % "9.1-901.jdbc4"
  22. )
  23.  
  24. (function() {
  25. var buttonValue = {};
  26. $("#submit").click(function() {
  27. $("input[type=button], input[type=file]").each(function($i) {
  28. var name = $(this).attr('name')
  29. buttonValue[name] = $(this).val();
  30. });
  31. console.log(JSON.stringify(buttonValue));//json object: [ex: {"firstButton":"button1","secondButton":"button2","file":"test.txt"} ], this json object should store in PostgreSQL database table as it is after clicking of Submit button.
  32. });
  33. }())
  34.  
  35. <input type='submit' value='Submit Json' id='submitJson'>
  36.  
  37. create table saveJsonData(id integer primary key, content json);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement