我的实体:
<entity name="Role" local-service="true" remote-service="false">
<column name="id" type="long" primary="true" />
<column name="system_id" type="int" />
<column name="user_id" type="int" />
<column name="comment" type="String" />
<column name="status_id" type="int" />
<column name="create_date" type="Date" />
<column name="update_date" type="Date" />
<column name="systemrequest_id" type="int" />
<order by="asc">
<order-column name="id" />
</order>
<finder name="bySystem" return-type="Collection">
<finder-column name="system_id"/>
</finder>
<finder name="byUser" return-type="Collection">
<finder-column name="user_id" />
<finder-column name="status_id" />
</finder>
<finder name="byId" return-type="gad">
<finder-column name="id" />
</finder>
</entity>
然后我将方法findBybyUser()
从RoleUtil.java
复制到RoleLocalServiceImpl.java
,如:
public java.util.List<com.example.model.gad> findBybyUser(
int user_id, int status_id) throws com.liferay.portal.kernel.exception.SystemException {
return RoleUtil.findBybyUser(user_id, status_id);
}
我已使用mvn liferay:build-service
最后,我想在我的portlet中的doView
方法中使用此finder方法:
@Override
public void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException {
List<PersonRoleHelper> personRoleList = new ArrayList<PersonRoleHelper>();
try {
List<User> userList = UserLocalServiceUtil.getUsers(1, UserLocalServiceUtil.getUsersCount());
for (User user : userList){
List<Role> roleList = RoleLocalServiceUtil.findBybyUser((int)user.getUserId(), 2);
logger.info ("list size: "+roleList.size());
}
personRoleList.add(roleList);
renderRequest.setAttribute("roles", personRoleList);
} catch (SystemException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
super.doView(renderRequest, renderResponse);
}
在日志中,我始终看到list size: 0
。我错过了什么?我应该如何访问finder方法才能获得结果?在SQL
中使用where user_id= 1 and status_id =2
返回结果