2015-10-20 70 views
1

我在2.4版本中设置了一个普通的Play Framework项目 - Java。创建自定义模型对象并返回它们的列表非常简单。我坚持使用ebean的对象。使用Play Framework在数据库中查找单个对象

但是,如何使用GET返回单个对象?

路线:

GET  /payments/:id   controllers.Application.getPayment(id: Long) 

而控制器试图找对象byId:

public Result getPayment(Long id) { 
    Payment payment = Payment.find.byId(id); 
    return ok(toJson(payment)); 
} 

但我的应用程序不知道是什么find是。

enter image description here

我跟着官方Play documentation指令。

编辑:我Payment.class

package models; 

import com.avaje.ebean.Model; 

import javax.persistence.Entity; 
import javax.persistence.Id; 

@Entity 
public class Payment extends Model { 

@Id 
Long id; 
String name; 

public Long getId() { 
    return id; 
} 

public void setId(Long id) { 
    this.id = id; 
} 

public String getName() { 
    return name; 
} 

public void setName(String name) { 
    this.name = name; 
} 
} 
+0

请您出示付款类 – cosmolev

+0

@cosmolev我更新我的帖子:) – Marcel

回答

1

您的付款类没有find场。

补充一点:

public static Finder<Long,Payment> find = new Finder<>(Long.class,Payment.class); 
+0

谢谢@cosmolev,它的作品! :) – Marcel

相关问题