[英]Validate registration user in web app (spring-boot + AngularJS)
我正在春季启动+日期+ AngularJS中实现一个Web项目。 客户端(angularjs)向Rest服务器发出请求(spring-boot)。 使用存储库开发的Spring Boot可以搜索CrudRepository的数据库。
@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中:
public <YourReturn> addAClient (@Valid @RequestBody ClientDTO clientDTO)
然后在DTO类上,您可以添加如下所示的简单检查:
客户DTO
@NotNull(message = "<null message>") @Length(max = 256, message = "<max size from client Name>") @NotBlank(message = "<not blank message>") public String getName() { return name; }
:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.