2015-10-20 68 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

相關問題