gpt4 book ai didi

playframework - 方法模型中操作数堆栈上的错误类型.MyModel

转载 作者:行者123 更新时间:2023-12-04 06:31:35 47 4
gpt4 key购买 nike

这是我的模型文档:

@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());
}
}
问题是,它在编译时抛出一个 VerifyError 异常,我发现唯一可以避免它的方法是注释该行并将其替换为 return null ,这不是很有效。
这是该异常的堆栈跟踪:
Caused by: java.lang.VerifyError: Bad type on operand stack in method models.Document.getUrl()Ljava/lang/String; at offset 13
at java.lang.Class.forName0(Native Method) ~[na:1.7.0_05]
at java.lang.Class.forName(Class.java:264) ~[na:1.7.0_05]
at play.db.ebean.EbeanPlugin.onStart(EbeanPlugin.java:69) ~[play_2.9.1.jar:2.0.2]
这是什么错误,如何在不丢失 getUrl 方法的情况下避免它?

最佳答案

我认为 Ebean 正试图在这里施展魔法。

我建议使用静态函数:

public static String buildUrl(String document) {
return controllers.routes.Documents.display(document.toLowerCase()).absoluteURL(Http.Context.current().request());
}

关于playframework - 方法模型中操作数堆栈上的错误类型.MyModel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11913460/

47 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com