步骤1:在com.bstek.dorado.sample.standardlesson.service.MessageService类中增加根据用户Id查找消息getMessageByEmployeeId方法,最终代码如下:
package com.bstek.dorado.sample.standardlesson.service; import java.util.Collection; import java.util.HashMap; import java.util.Map; import javax.annotation.Resource; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import com.bstek.dorado.annotation.DataProvider; import com.bstek.dorado.annotation.DataResolver; import com.bstek.dorado.data.provider.Page; import com.bstek.dorado.sample.standardlesson.dao.SlEmployeeDao; import com.bstek.dorado.sample.standardlesson.dao.SlMessageDao; import com.bstek.dorado.sample.standardlesson.entity.SlEmployee; import com.bstek.dorado.sample.standardlesson.entity.SlMessage; @Component public class MessageService { @Resource private SlMessageDao slMessageDao; @Resource private SlEmployeeDao slEmployeeDao; @DataResolver @Transactional public void saveMessages(Collection<SlEmployee> slEmployees){ for(SlEmployee employee:slEmployees){ Collection<SlMessage> messages = employee.getSlMessageSet(); for(SlMessage message:messages){ //维护关联关系 message.setSlEmployee(employee); } slMessageDao.persistEntities(messages); } } @DataProvider public void getMessageByEmployeeId(Page<SlMessage> page, Integer employeeId){ String hql = "from SlMessage where slEmployee.employeeId = :employeeId"; Map param = new HashMap(); param.put("employeeId", employeeId); slMessageDao.find(page,hql,param); } }
其中方法接受一个employeeId参数,并以此参数查询对应的消息列表。