15
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

設定ファイルとURLからパラメータを読み込む

Last updated at Posted at 2013-05-07

##設定ファイル(application.conf)内の値を読み込む
val config = Configuration(ConfigFactory.load())
val hoge = config.getString("hoge.fuga").getOrElse("fuga")

##独自に作った設定ファイル内の値を読み込む
val config = Configuration(ConfigFactory.load(ConfigFactory.parseFileAnySyntax(new File("conf/hoge.conf"))))
val hoge = config.getString("hoge.fuga").getOrElse("fuga")

##URLから引数を読み込む
###routesを編集

#リクエストパラメータで受け取る場合
GET /messages controllers.Application.messages(id: String, name:String)
 
#パスで受け取る場合
GET /messages/:id/:name controllers.Application.messages(id: String, name:String)

###コントローラ(Application.scala)を編集

def messages(id: String, name: String) = Action {
    ...
}

##参考
Configurationの内部ではTypesafeのconfigが使用されている

15
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?