- 1、本文档共6页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
play1.2.4学习笔记
play1.2.4版本:
play启动是main方法,首先进行一些初始化操作,然后开启http监听。
application.conf配置:
(1) db=mem,默认,使用内存database,play重启后数据丢失。
(2) 连接mysql时设置:
db=mysql://root:root@localhost/play
注意:以test模式(play test )启动时,每次application启动时会重新创建数据库表,历史数据也会清掉(不明白为什么这么设计?)。 正常启动(play run)时,不会对历史数据有影响。
(3)jpa.ddl值为update时在应用启动时自动创建表,为none时需首先在mysql中手工创建表。
jpa.ddl=update
(4)使用Play.configuration得到conf/application.conf中配置的参数值,Play.configuration.getProperty方法得到配置的某个参数值 。
play的JPA底层使用的是Hibernate实现。
两种方式实现ORM:
(1)extends play.db.jpa.Model类:
例:自动生成key id;不需要列对应,属性名称即为数据库表字段名;属性为public,不需要生成getter/setter方法。另外,还可以添加一些功能操作的方法,不是传统的bean。
package models;
import javax.persistence.Entity;
import play.db.jpa.Model;
@Entity
public class User extends Model {
public String email;
public String password;
public String fullname;
public String isAdmin;
public User(String email, String password, String fullname) {
this.email = email;
this.password = password;
this.fullname = fullname;
}
} By default, the table name is ‘User’. If you change the configuration to use a database where ‘user’ is a reserved keyword, then you will need to specify a different table name for the JPA mapping. To do this, annotate the User class with @Table(name=“blog_user”).
(2)extends play.db.jpa.JPASupport类(@Deprecated):
package models;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import play.db.jpa.JPASupport;
@Entity
@Table(name = table_news)
public class News extends JPASupport{
@Id
@Column(name=C_ID)
private Long cId;
@Column(name=C_TITLE)
private String cTitle;
public News(Long id, String title) {
super();
cId = id;
cTitle = title;
}
public Long getCId() {
return cId;
}
public void setCId(Long id) {
cId = id;
}
public String getCTitle() {
return cTitle;
}
public void setCTitle(String title) {
cTitle = title;
}
}
模板-表示式语言符号
可参见/documentation/1.2.4/templates#syntax
# {}: 表示引用
文档评论(0)