質問編集履歴
1
モデル(リポジトリ)の追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -80,7 +80,9 @@
|
|
80
80
|
case class Person(id: Int, name: String, mail: String, tel: String)
|
81
81
|
case class PersonForm(name: String, mail: String, tel: String)
|
82
82
|
```
|
83
|
+
|
84
|
+
|
83
|
-
### index.
|
85
|
+
### index.scala.html (テンプレート)
|
84
86
|
```
|
85
87
|
@(message: String, data: Seq[models.Person])(implicit request: MessagesRequestHeader)
|
86
88
|
|
@@ -93,7 +95,44 @@
|
|
93
95
|
</ul>
|
94
96
|
}
|
95
97
|
```
|
98
|
+
### PresonRepository.scala (リポジトリ)
|
99
|
+
```
|
100
|
+
package models
|
96
101
|
|
102
|
+
import javax.inject.{ Inject, Singleton }
|
103
|
+
import play.api.db.slick.DatabaseConfigProvider
|
104
|
+
import slick.jdbc.JdbcProfile
|
105
|
+
|
106
|
+
import scala.concurrent.{ Future, ExecutionContext }
|
107
|
+
|
108
|
+
@Singleton
|
109
|
+
class PersonRepository @Inject()
|
110
|
+
(dbConfigProvider: DatabaseConfigProvider)
|
111
|
+
(implicit ec: ExecutionContext) {
|
112
|
+
|
113
|
+
private val dbConfig = dbConfigProvider.get[JdbcProfile]
|
114
|
+
|
115
|
+
import dbConfig._
|
116
|
+
import profile.api._
|
117
|
+
|
118
|
+
private class PeopleTable(tag: Tag)
|
119
|
+
extends Table[Person](tag, "people") {
|
120
|
+
def id = column[Int]("id", O.PrimaryKey, O.AutoInc)
|
121
|
+
def name = column[String]("name")
|
122
|
+
def mail = column[String]("mail")
|
123
|
+
def tel = column[String]("tel")
|
124
|
+
|
125
|
+
def * = (id, name, mail, tel) <>
|
126
|
+
((Person.apply _).tupled, Person.unapply)
|
127
|
+
}
|
128
|
+
|
129
|
+
private val people = TableQuery[PeopleTable]
|
130
|
+
|
131
|
+
def list(): Future[Seq[Person]] = db.run {
|
132
|
+
people.result
|
133
|
+
}
|
134
|
+
}
|
135
|
+
```
|
97
136
|
### バージョン
|
98
137
|
|
99
138
|
Scala 2.12.6
|