1

I have done the following things

=> controllers.Application

object Application extends Controller {

  val studentForm = Form(

    mapping(

      "FirstName" -> text,

      "MiddleName" -> text,

      "LastName" -> text,

      "RollNumber" -> number,

      "TemporaryAddress" -> text,

      "PermanentAddress" -> text,

      "Faculty" -> text,

      "Section" -> text,

      "ContactNumber" -> number,

      "Email" -> text

    )(StudentInfo.apply)(StudentInfo.unapply)

  )

  def saveForm = Action {/* implicit request =>

    studentForm.bindFromRequest.fold(

      errors => (BadRequest("Error")),

      res => */ Ok(views.html.forms(studentForm))


    }


   }

=> models

package models


import play.api.libs.json.Json


/**

  * Created by milan on 9/26/16.

  */

case class StudentInfo (

  FirstName: String,

  MiddleName:String,

  LastName:String,

  RollNumber:Int,

  TemporaryAddress:String,

  PermantAddress:String,

  Faculty:String,

  Section:String,

  ContactNumber:Int,

  Email:String)

  {


   }
object StudentInfo {

  implicit val info = Json.format[StudentInfo]


}

=> routes

GET  /forms                               controllers.Application.saveForm

This gives the form.Now I need to connect database without using views i.e

with json.And I need to use Mongodb and reactiveMongo.Can Anyone help me to

do this?

Kevin Yan
  • 1,236
  • 11
  • 19
AAA
  • 354
  • 1
  • 3
  • 14
  • Please provide the things you have tried. If you need a general advice, look around on StackOverflow and you'll find. You may want to create a Future which writes your data to the DB. Here you find the info for reactive mongo: http://reactivemongo.org/releases/0.11/documentation/tutorial/getstarted.html – sascha10000 Sep 30 '16 at 00:00
  • @sascha10000 def create(name:String,rollNumber:Int) = Action.async { val json = Json.obj( "name" -> name , "rollNumber" -> rollNumber, "created" -> new java.util.Date().getTime()) collection.insert(json).map(lastError => Ok("Mongo LastError: %s".format(lastError))) } And i got No Json serializer as JsObject found for type play.api.libs.json.JsObject error – AAA Oct 05 '16 at 09:02
  • Please modify your questing accordingly. I don't have the time and pace to get my head around this stuff unformatted. And Provide the relevant part of your error. – sascha10000 Oct 06 '16 at 12:11

0 Answers0