Playframework 方法models.MyModel中的操作数堆栈类型错误
这是我的模型文档:Playframework 方法models.MyModel中的操作数堆栈类型错误,playframework,playframework-2.0,java-7,Playframework,Playframework 2.0,Java 7,这是我的模型文档: @Entity @Table(name = "documents") public class Document extends Model { @Id public Long id; @Constraints.Required @Formats.NonEmpty @Column(nullable=false) public String document; public static M
@Entity
@Table(name = "documents")
public class Document extends Model {
@Id
public Long id;
@Constraints.Required
@Formats.NonEmpty
@Column(nullable=false)
public String document;
public static Model.Finder<Long,Document> find = new Model.Finder(Long.class, Document.class);
// Will return an absolute URL to this document
public String getUrl() {
return controllers.routes.Documents.display(document.toLowerCase()).absoluteURL(Http.Context.current().request());
}
}
这个错误是什么?我如何避免它而不丢失getUrl方法?我认为Ebian正在尝试在这里发挥一些魔力 我建议使用静态函数:
public static String buildUrl(String document) {
return controllers.routes.Documents.display(document.toLowerCase()).absoluteURL(Http.Context.current().request());
}
我今天也有同样的问题。我尝试应用上面建议的相同逻辑(使用问题方法的静态函数),但没有效果。我重新开始播放、清理、重新编译,问题就消失了 以下是我使用的播放命令
exit
play
clean
run
你可以加上
@Transient
对方法进行注释,它就可以工作了 你的代码很奇怪,因为你的属性
document
是String类型的,然后你调用document.name()
,但是方法name()
不是String类的一部分…很抱歉,我删除了所有无用的东西,简化了代码,但是忘记了那部分!遗憾的是,即使我拥有该模型的实例,我也必须使用静态方法:/t尝试保留非静态方法,并将其从getUrl
重命名为buildUlr
。javax.persistence.transientThank,刚刚救了我一天!
@Transient