我目前正在进行一项服务,我必须使用服务验证。我们通过存储库在数据库中存储的请求类从客户端获取输入,我们必须提供注释和我们必须的位置给出bindingresult参数。当我们调用服务时,必须进行验证。在这里,我附上了示例代码。
这是我尝试实施验证的服务类
public long create(@Valid Document document,BindingResult bindingResult,DocumentResourceRequest DocumentResourceRequest,
long agreementId) throws Exception {
// TODO Auto-generated method stub
logger.info("In DocumentServiceImpl createLoanDocument");
Document documentObject = new Document(new lend(
agreementId));
documentObject.setDocumentType(DocumentResourceRequest
.getDocumentType());
documentObject.setDocumentDetails(DocumentResourceRequest
.getDocumentDetails());
documentObject.setRemarks(DocumentResourceRequest.getRemarks());
documentObject.setDocumentStatus(DocumentResourceRequest
.getDocumentStatus());
documentObject.setCreatedBy(DocumentResourceRequest
.getCreatedBy());
documentObject.setCreatedOn(new Date());
try {
if(document != null)
{
document = loanDocumentRepo.saveAndFlush(documentObject);//DocumentRepository
}else(bindingResult.getAllErrors())//if getting errors
{
}
} catch (Exception e) {
throw new Exception("Error in persisting Document-->" + e);
}
return document.getId();
}