|
|||||||||
play26 の変更点
#author("2019-06-24T03:20:01+00:00","default:pentacle","pentacle")
Play2.6 導入方法
* install [#aaf17761]
** java [#mfcfafcf]
JAVA_HOME と PATH で javac が使えるようにしておくこと
** download [#p65ca73a]
ebean 版
https://developer.lightbend.com/start/?group=play&project=play-java-ebean-example
** rename [#qacbcd45]
mv play-java-ebean-example play26
''build.sbt''
name := "play26"
** eclipse plugin [#t33b4b80]
''project/plugins.sbt''
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "5.2.4")
./sbt eclipse
初回sbt は時間がかかるので気長に待つ~
eclipse から既存プロジェクトの import
** postgres [#ca8349b9]
''build.sbt''
libraryDependencies += "org.postgresql" % "postgresql" % "9.4-1201-jdbc41"
psql -U postgres -c "create database play26"
''conf/application.conf''
db.default.driver=org.postgresql.Driver
db.default.url="jdbc:postgresql://localhost:5432/play26"
db.default.username="postgres"
db.default.password="pass"
''.bashrc''
export SBT_OPTS="-Xmx1536M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=384M"
./sbt run
*** 確認 [#mf2bf2ea]
http://localhost:9000
** velocity [#pfdd2d01]
scala の html template が慣れないので velocity を導入
''build.sbt''
libraryDependencies += "org.apache.velocity" % "velocity" % "1.7"
libraryDependencies += "velocity-tools" % "velocity-tools" % "1.4"
./sbt eclipse
''conf/templates/default/hello.html''
hello $name
''app/controllers/HomeController.java''
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
public HomeController (){
Velocity.setProperty("file.resource.loader.path", "conf/templates/");
Velocity.init();
}
public Result hello(){
StringWriter writer = new StringWriter();
Template template = Velocity.getTemplate("default/hello.html", "UTF-8");
VelocityContext vc = new VelocityContext();
vc .put("name", "scott");
template.merge(vc, writer);
String result = writer.toString();
return Results.ok(result).as("text/html; charset=UTF-8");
}
''conf/routes''
GET /hello controllers.HomeController.hello()
*** 確認 [#h0163b26]
localhost:9000/hello
** ebean [#i4679252]
ebean の ORM (model を書き換えると自動的に DB のテーブルを書き換える )を活性化する~
これをやるとDBの中身が消えるので注意~
''evolutions/default/1.sql''
一行目に追加
# --- Created by Ebean DDL
*** ベストプラクティス的なもの [#d0c780be]
- models 以下にあるclass (@Entity付き)のフィールドを追加すると自動で変わる
- ある程度開発が終わったら、自動生成をやめる(先ほどの1行目を消す)
- 2.sql, 3.sql ... を作って自分で DDL 作成する
|
|||||||||