我在spring boot + date + AngularJS中实现了一个web项目。客户端(angularjs)向Rest服务器发出请求(spring-boot)。使用存储库进行Spring引导来开发搜索CrudRepository的数据库。在Web应用程序中验证注册用户(spring-boot + AngularJS)
@RepositoryRestResource
public interface ClientRepository extends CrudRepository< Client , Integer > {
List<Client> findAll();
}
只需要编辑存储库的保存功能。我试图创建一个运行了保存但不工作的服务层。
@Component("clientService")
@Transactional
public class ClientRepositoryImpl implements ClientService{
private final ClientRepository clientRepository;
public ClientRepositoryImpl(ClientRepository clientRepository) {
this.clientRepository = clientRepository;
}
@Override
public String addClient(Client saved) {
// ....
if(this.clientRepository.save(saved) != null)
return "OK";
else
return "NOK";
}
}
任何人都可以提供一个想法如何在调用保存库之前创建一些逻辑吗?我正在实施注册,需要验证在服务器端输入的数据,并且不知道要在存储库之前进行验证。由于客户端使用参数进行呼叫休息(/客户端)。
在您的服务器端,当您收到REST调用,你必须添加到您的restController:
感谢您的答复,但我需要的,例如,转换为散列密码。我需要覆盖保存。 – user2989745
好的。你的意思是你需要更新值(即改变来自视图的值),所以你需要创建一个特定的方法和一个类来做到这一点。为了做到这一点,您需要一个特殊的组件/服务来将DTO转换为“商务类”**(最佳选项**)。如果你只需要做一个简单的修改,你可以创建一个_ENUM_并传递给save方法。 – Ogma
“需要一个特殊的组件/服务来将DTO转换为”商务舱“。”我的问题是,我不知道该怎么做..任何想法? – user2989745