first commit

This commit is contained in:
2025-10-09 10:36:56 +02:00
commit 81a1fbfdb9
21 changed files with 347 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
package controllers
import javax.inject._
import play.api.mvc._
import play.api.data._
import play.api.data.Forms._
case class $model;format="Camel"$Data(name: String, age: Int)
object $model;format="Camel"$Data {
def unapply(data: $model;format="Camel"$Data): Option[(String, Int)] = Some((data.name, data.age))
}
// NOTE: Add the following to conf/routes to enable compilation of this class:
/*
GET /$model;format="camel"$ controllers.$model;format="Camel"$Controller.$model;format="camel"$Get()
POST /$model;format="camel"$ controllers.$model;format="Camel"$Controller.$model;format="camel"$Post()
*/
/**
* $model;format="Camel"$ form controller for Play Scala
*/
class $model;format="Camel"$Controller @Inject()(mcc: MessagesControllerComponents) extends MessagesAbstractController(mcc) {
val $model;format="camel"$Form = Form(
mapping(
"name" -> text,
"age" -> number
)($model;format="Camel"$Data.apply)($model;format="Camel"$Data.unapply)
)
def $model;format="camel"$Get() = Action { implicit request: MessagesRequest[AnyContent] =>
Ok(views.html.$model;format="camel"$.form($model;format="camel"$Form))
}
def $model;format="camel"$Post() = Action { implicit request: MessagesRequest[AnyContent] =>
$model;format="camel"$Form.bindFromRequest().fold(
formWithErrors => {
// binding failure, you retrieve the form containing errors:
BadRequest(views.html.$model;format="camel"$.form(formWithErrors))
},
$model;format="camel"$Data => {
/* binding success, you get the actual value. */
/* flashing uses a short lived cookie */
Redirect(routes.$model;format="Camel"$Controller.$model;format="camel"$Get()).flashing("success" -> ("Successful " + $model;format="camel"$Data.toString))
}
)
}
}

View File

@@ -0,0 +1,12 @@
@($model;format="camel"$Form: Form[$model;format="Camel"$Data])(implicit request: MessagesRequestHeader)
<h1>$model;format="camel"$ form</h1>
@request.flash.get("success").getOrElse("")
@helper.form(action = routes.$model;format="Camel"$Controller.$model;format="camel"$Post()) {
@helper.CSRF.formField
@helper.inputText($model;format="camel"$Form("name"))
@helper.inputText($model;format="camel"$Form("age"))
<input type="submit" value="submit"/>
}