play 中使用己有 database 生成 models

用 JPAGEN http://www.playframework.org/modules/jpagen-1.0/home 可以生成

install

play install jpagen

配置

加入 application.conf

* The jpagen module
module.jpagen=${play.path}/modules/jpagen

没有用,我装的是 1.0 改为

* The jpagen module
module.jpagen=${play.path}/modules/jpagen-1.0.2

好了

指定 mode

还是在 application.conf 中加入

jpagen.mode=ORACLE

因为我用的 oracle

使用

生成 table-list

play jpagen:create-list ./

报错

~ Generating the conf/table_list.conf file from database using metadata
~ 
Listening for transport dt_socket at address: 8000
13:30:57,804 INFO  ~ Starting /home/bigzhu/Dropbox/src/imap2
13:30:57,810 WARN  ~ Declaring modules in application.conf is deprecated. Use dependencies.yml instead (module.jpagen)
13:30:57,810 INFO  ~ Module jpagen is available (/home/bigzhu/program/play/modules/jpagen-1.0)
13:30:58,517 WARN  ~ You're running Play! in DEV mode
13:30:58,518 INFO  ~ Exclude pattern: []
13:30:58,518 INFO  ~ Include pattern: []
13:30:58,518 INFO  ~ driver: oracle.jdbc.driver.OracleDriver url: jdbc:oracle:thin:@localhost:1521:xe user: imap password: imap
13:30:58,582 INFO  ~ MLog clients using log4j logging.
13:31:00,121 INFO  ~ templateFile: list.tmpl
13:31:01,532 ERROR ~ 
java.lang.NullPointerException
	at play.modules.jpagen.ListGenerator.main(ListGenerator.java:64)

application.conf 配置文件中加入

db.default.schema=""

可以生成了,不过是个空的

~ Generating the conf/table_list.conf file from database using metadata
~ 
Listening for transport dt_socket at address: 8000
13:34:27,290 INFO  ~ Starting /home/bigzhu/Dropbox/src/imap2
13:34:27,295 WARN  ~ Declaring modules in application.conf is deprecated. Use dependencies.yml instead (module.jpagen)
13:34:27,295 INFO  ~ Module jpagen is available (/home/bigzhu/program/play/modules/jpagen-1.0)
13:34:28,126 WARN  ~ You're running Play! in DEV mode
13:34:28,127 INFO  ~ Exclude pattern: []
13:34:28,127 INFO  ~ Include pattern: []
13:34:28,127 INFO  ~ driver: oracle.jdbc.driver.OracleDriver url: jdbc:oracle:thin:@localhost:1521:xe user: imap password: imap
13:34:28,192 INFO  ~ MLog clients using log4j logging.
13:34:28,553 INFO  ~ templateFile: list.tmpl
13:34:30,349 INFO  ~ Process finished: Generated conf/table_list.conf with 0 tables

自己编辑,加入表名

gvim conf/table_list.conf
* Table List
* Connection used: jdbc:oracle:thin:@localhost:1521:xe

SS_TAB
ES_TAB
CLASSES
BIAOHUIFUWU
BH_USERLAYER

生成 models

play jpagen:generate ./

就会按指定的表名在 app/models 下 来生成 java models 了

指定的表名最好按规范来,这样建立出的 java class 也比较规范

比如 userinfo 表,就写为 UserInfo

[让 play 不要自作主张的添加 id 字段](让 play 不要自作主张的添加 id 字段.md)