0
我是網絡服務和Spring的新手。我有這樣一個Web服務方法:在web方法,服務層或DAO層中創建服務響應?
@WebMethod(operationName = "docSearch")
public ServiceResponse docSearch(@WebParam(name = "docNum") String docNum) {
//TODO lots of TODOs here:
docService = getDocService();
ServiceResponse serviceResponse = docService.docSearchService(docNum);
return serviceResponse;
}
使用這個服務:
@Transactional
public ServiceResponse docSearchService(ServiceRequest serviceRequest, String docNum) {
//TODO lots of TODOs here:
ServiceResponse serviceResponse = new ServiceResponse();
serviceResponse = docDao.docSearchDAO(serviceRequest, docNum);
return serviceResponse;
}
和相應的DAO是:
public ServiceResponse docSearchDAO(ServiceRequest serviceRequest, String docNum) {
Session session = sessionFactory.getCurrentSession();
List<doc> temp = session.createCriteria(Doc.class)
.add(Restrictions.eq("id", docNum))
.list();
if (temp != null && temp.size() > 0) {
serviceResponse.setDescription("Service response successfully implemented);
return serviceResponse;
} else {
serviceResponse.setDescription("Service response was not successfully implemented);
return serviceResponse;
}
}
我不知道什麼是填充的最好方式在Web方法的這個ServiceResponse對象中,在服務層還是在DAO層?
非常感謝明確說明和鏈接。我一定會看看你的建議! – lamostreta