我是 Web 服务和 Spring 的新手。我有一个这样的网络服务方法:
@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 方法、服务层或 DAO 层中填充此 ServiceResponse 对象的最佳方法是什么?