Red > Green > Refactor > Red

cycle is based on desire

Play framework(Java) で initialize, routing, view 作成, controller 作成して画面表示まで

大前提

initialize

$ cd activator-1.3.5-minimal/
$ ./activator new
Browse the list of templates: http://typesafe.com/activator/templates
Choose from these featured templates or enSter a template name:
  1) minimal-akka-java-seed
  2) minimal-akka-scala-seed
  3) minimal-java
  4) minimal-scala
  5) play-java
  6) play-scala
(hit tab to see a list of all templates)
> play-java
Enter a name for your application (just press enter for 'play-java')
> yourAppName

下記では、上の操作が終了し

$ cd yourAppName

を行っている前提で話を進める

routing

$ YOURE_DITOR conf/routes
GET /  controllers.Application.index()

# add below line
GET /article/list  controllers.Article.list()

create view

$ mkdir app/views/article
$ YOUR_EDITOR app/views/article/list.scala.html
/* template extension is only 'scala', no suite for java */
<h1>Article List</h1>

create controller

$ YOUREDITOR app/controllers/Article.java
/* edit belows */
1 package controllers;
2
3 import play.*;
4 import play.mvc.*;
5
6 import views.html.*;
7
8 public class Article extends Controller {
9   public Result list() {
10     return ok(views.html.article.list.render());
11   }
12 }

run server

$ ./activator run

以下リンクに遷移すると「Article List」が表示されているはず

http://localhost:9000/article/list