0

I have a Product model that has some basic attributes,

package models;

import java.util.*;
import javax.persistence.*;

import play.db.ebean.*;
import play.data.validation.*;

@Entity
public class Product extends Model {

    public String name;

    public String description;

    public static Finder<Long,Item> find = new Finder<Long,Item>(
        Long.class, Item.class
    );

}

a controller function that uses find to attain and pass a List<Product> to the desired view,

package controllers;

import play.*;
import play.mvc.*;

import views.html.*;

import models.Product;

public class Application extends Controller {

    public static Result allProducts() {
        return ok(product_page.render(Product.find.all()));
    }

}

and the stated view that iterates over the list and displays these properties.

@(products: List[Product])

<h1>Here are the products:</h1>

<ul>
@for(product <- products) {
    <li>@product.getName()</li>
    <ul>
        <li>@product.getDescription()</li>
    </ul>
}
</ul>

Everything looks fine (at least to me)... but the compiler tells me this:

value getName is not a member of models.Product 

What am I doing wrong? (the route is fine, application.conf is setup correctly, evolutions are correct as well...)

4

2 に答える 2

0

Productgetterメソッドがありません

于 2012-05-10T05:17:05.630 に答える
0

使用する:

 <li>@product.description</li>

ところで:あなたのファインダーは、現在のモデルのクラスを2番目のタイプとして使用する必要があります

public static Finder<Long,Product> find = new Finder<Long,Product>(
    Long.class, Product.class
);
于 2012-05-10T07:05:02.353 に答える