我是这个框架的新手! 我想生成模型的分页器以在模板中显示我的lits。
我使用Play-java,Ebean,scala.html模板。
谢谢!
我有这个!
型号:
public static Finder<String,User> find = new Finder(
String.class, User.class
);
public static List<User> all(){
return find.all();
}
控制器:
public class UserController extends Controller {
public Result index() {
return ok(list_users.render(User.all()));
}
}
查看(list_user.scala.html)
<table>
<thead>
<tr>
<th>Email</th>
<th>Name</th>
<th>Last Name</th>
</tr>
</thead>
<tbody>
@for(user<- users){
<tr>
<td>@user.getEmail()</td>
<td>@user.getName()</td>
<td>@user.getLastName()</td>
</tr>
}
</tbody>
</table>
答案 0 :(得分:0)
定义一个函数,该函数从数据源获取给定页面配置的页面。
public static PagedList<User> page(int page, int pageSize, String sortBy, String order, String filter) {
return
find.where()
.ilike("first_name", "%" + filter + "%")
.orderBy(sortBy + " " + order)
.fetch("*")
.findPagedList(page, pageSize);
}
然后定义一个Action,用于渲染填充了对象的模板
public Result list(int page, String sortBy, String order, String filter) {
return ok(
views.html.list.render(
page(page, 10, sortBy, order, filter),
sortBy, order, filter
)
);
}
这Complete code Sample会给你更多的信息。