ちょっと悩んだのでメモ
PlayFrameworkで既存のMySQLにつなぐためには
テーブルはこれ
1 2 3 4 5 6 7 8 9 | use sampled ; create table sample( id integer, name varchar(32) ) ; create unique index idx_sampleTable on sampleTable(id) ; |
まずモデル
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | package models; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; import play.db.ebean.model; @Entity @Table(name="sample") public class Sample extends Model { @Column(name="id") @Id public integer id; @Column(name="name") public String name; public String toString(){ return id+","+name; } } |
application.conf
1 2 3 4 5 6 7 8 9 10 11 | .. db.default.driver=com.mysql.jdbc.Driver db.default.url="jdbc:mysql://dbserver/sampledb" db.default.user=root db.default.password=password evolutionplugin=disabled ebean.default="models.*" .. |
これを使って、ViewとControllerにつなげれやればおっけー