3
這是我在這裏的第一篇文章:)我有一個CRUD模塊的問題。我想在列表中添加更多過濾器,但我無法理解Factory Model。我有這樣的代碼:過濾crud列表問題玩!框架
@With(Secure.class)
public class Contacts extends CRUD {
public static void list(int page,String search,int origine,String searchFields, String orderBy, String order) {
ObjectType type = ObjectType.get(getControllerClass());
notFoundIfNull(type);
if (page < 1) {
page = 1;
}
//System.out.println(type);
List<Model> contacts = Model.Manager.factoryFor(Contact.class).fetch((page - 1) * getPageSize(), getPageSize(), orderBy, order, searchFields == null ? new ArrayList<String>() : Arrays.asList(searchFields.split("[ ]")), search, (String) request.args.get("where"));
System.out.println(contacts);
List<Model> objects = type.findPage(page, search, searchFields, orderBy, order, (String) request.args.get("where"));
Long count = type.count(search, searchFields, (String) request.args.get("where"));
Long totalCount = type.count(null, null, (String) request.args.get("where"));
// Liste des origines
List<Origine> origines = Origine.find("order by nom asc").fetch();
List<Employe> employes = Employe.find("order by nom asc").fetch();
try {
render(type, objects, count, totalCount, page, orderBy, order, origines,employes);
} catch (TemplateNotFoundException e) {
render("CRUD/list.html", type, objects, count, totalCount, page, orderBy, order, origines, employes);
}
}
}
我想搜索的申請「原產」和「僱工」我該怎麼辦呢?感謝您的幫助。 :)
你希望做什麼樣的過濾器? – mandubian
也許我沒有使用好的術語...這是更多的添加字段來搜索數據。例如,我有一個聯繫人,在這張表中我與僱主(OnetoMany)和Origine有關係。我想顯示與特定僱員的所有聯繫人(在SQL等於SELECT * FROM聯繫人地址id_employe = my_post_value) –
您是否看過JPAPlugin.JPAModelLoader類中的函數fetch和getSearchQueries?它在那裏,搜索字段被分析! – mandubian