如果您只想获取所有用户的电子邮件地址列表,则可以使用以下代码:
DynamicQuery dynamicQuery = UserLocalServiceUtil.dynamicQuery();
dynamicQuery.add(RestrictionsFactoryUtil.isNotNull("emailAddress"));
// this is the statement which would cause to return only a list of emails
dynamicQuery.setProjection(ProjectionFactoryUtil.property("emailAddress"));
int startOfList = QueryUtil.ALL_POS;
int endOfList = QueryUtil.ALL_POS; // this will fetch all the Users
// note: it returns a list of String
List<String> emailAddresses = (List<String>) UserLocalServiceUtil.dynamicQuery(dynamicQuery, startOfList, endOfList);
如果你想获取User
s 那么你的代码就可以了,只需要更改startOfList
andendOfList
字段:
DynamicQuery dynamicQuery = UserLocalServiceUtil.dynamicQuery();
dynamicQuery.add(RestrictionsFactoryUtil.isNotNull("emailAddress"));
int startOfList = QueryUtil.ALL_POS;
int endOfList = QueryUtil.ALL_POS;
List<User> users = (List<User>) UserLocalServiceUtil.dynamicQuery(dynamicQuery, startOfList, endOfList);
或者如果您不想检查任何条件并想获取User
s 那么只需使用:
List<User> users = UserLocalServiceUtil.getUsers(startOfList, endOfList);
关于您看到的异常,它们与您发布的代码无关。这些可能是由于 Java 类或 JSP 中的一些其他代码造成的。如果您放置完整的堆栈跟踪,那么我们可以提供帮助。