I'm using a repostiroy rest resource service and currently I need to implement a method to import the data from a excel file into my database. I don't see how I can do with spring repository rest resource? since it's an interface. do I use restController or does it have a way to do both?
The standard flow would be:
Create a repository file
@Repository
public interface RepositoryClass extends JpaRepository<T, ID>{}
The JpaRepository already have save() and saveAll() methods(1)
In service create a method that read the data and saves it in the database
@Service
public class ServiceClass{
// ...some code
public void importData(// ... parameters){
// open the excel file and import the data in an ArrayList for exemple
repositoryClass.saveAll(arrayWithData);
}
}
The last step is to create a endpoint in the controller which calls the method that is written in service.