package models
import java.util.{Date}
import play.api.db._
import play.api.Play.current
import anorm._
import anorm.SqlParser._
import scala.language.postfixOps
case class Post(bid: Pk[Long] = NotAssigned, userId: String, content: String, regDate: Option[Date])
object Post{
val simple = {
get[Pk[Long]]("test.bid") ~
get[String]("test.userId") ~
get[String]("test.content") ~
get[Option[Date]]("test.regDate") map {
case bid~userId~content~regDate => Post(bid,userId,content,regDate);
}
}
def list() = {
DB.withConnection {implicit connection =>
val posts = SQL(
"""
select * from test
"""
).as(Post.simple *)
posts
}
}
}
package controllers
import play.api._
import play.api.mvc._
import models.Post
object Application extends Controller {
def board = Action {implicit request =>
Ok(views.html.board(
Post.list()
))
}
}
@(posts: List[Post])
@main("This is board!") {
@posts
}
@(title: String)(content: Html)
<!DOCTYPE html>
<html>
<head>
<title>@title</title>
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")">
<link rel="shortcut icon" type="image/png" href="@routes.Assets.at("images/favicon.png")">
<script src="@routes.Assets.at("javascripts/jquery-1.9.0.min.js")" type="text/javascript"></script>
</head>
<body>
@content
</body>
</html>
name := "board"
version := "1.0-SNAPSHOT"
libraryDependencies ++= Seq(
jdbc,
anorm,
cache,
"mysql" % "mysql-connector-java" % "5.1.33"
)
play.Project.playScalaSettings
'소프트웨어 개발 > Scala - Functional' 카테고리의 다른 글
coffee script (0) | 2014.12.15 |
---|---|
scala 참조 (0) | 2014.12.15 |
less (0) | 2014.12.12 |
Label (0) | 2014.12.11 |
Typesafe activator 모든주소에서 0.0.0.0 listening 하기 (0) | 2014.09.18 |