Quantcast
Channel: プログラム の個人的なメモ
Viewing all articles
Browse latest Browse all 860

【Play Framework】Play Framework [3] ~ 入門編 / モデルの設定 ~

$
0
0

はじめに

http://blogs.yahoo.co.jp/dk521123/36077858.html
で、HelloWorldを作成したのが、今度はモデルおよびDBアクセスを絡めてみる
Eclipse のプロジェクトは、上記の関連記事のものを再利用する。

注意

 * play2.4からモデルの扱いが変わったらしい

環境設定

http://mofmof721.hatenablog.com/entry/2015/12/27/214818
が参考になる。
対象環境
 * DB : MySQL

conf/application.conf

・・・略・・・
play.evolutions {
  # You can disable evolutions for a specific datasource if necessary
  # コメントを外す
  db.default.enabled = false
}

・・・略・・・

・・・略・・・
db {
  # You can declare as many datasources as you want.
  # By convention, the default datasource is named `default`

  # https://www.playframework.com/documentation/latest/Developing-with-the-H2-Database
  #default.driver = org.h2.Driver
  #default.url = "jdbc:h2:mem:play"
  #default.username = sa
  #default.password = ""
  
  # 追加
  db.default.driver=com.mysql.jdbc.Driver
  db.default.url="jdbc:mysql://localhost:3306/sampledb?useSSL=false&useUnicode=true&characterEncoding=UTF-8"
  db.default.username=username
  db.default.password="password"
  
  # You can turn on SQL logging for any datasource
  # https://www.playframework.com/documentation/latest/Highlights25#Logging-SQL-statements
  #default.logSql=true
}

# 追加
ebean.default = ["models.*"]

【プロジェクト名】/project/plugins.sbt

// Play Ebean support, to enable, uncomment this line, and enable in your build.sbt using
// enablePlugins(PlayEbean). ↓コメントアウトした
addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "1.0.0")

build.sbt

version := "1.0-SNAPSHOT"

# 修正
lazy val root = (project in file(".")).enablePlugins(PlayJava,PlayEbean)

scalaVersion := "2.11.7"

libraryDependencies ++= Seq(
  javaJdbc,
  cache,
  javaWs,
  "mysql" % "mysql-connector-java" % "5.1.20" # 追加
)



関連記事

Play Framework [1] ~環境構築 編~

http://blogs.yahoo.co.jp/dk521123/36058991.html

Play Framework [2] ~入門編 / Hello World ~

http://blogs.yahoo.co.jp/dk521123/36077858.html

Play Framework の環境構築時のトラブルシューティング

http://blogs.yahoo.co.jp/dk521123/36068396.html

O/Rマッパー [1] ~ Doma2 ~

http://blogs.yahoo.co.jp/dk521123/36044963.html

Viewing all articles
Browse latest Browse all 860

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>