1

I'm trying to figure out the Spring way of doing things as I'm new to the platform. I have a repository declared as follow:

public interface ScreenshotRepository extends JpaRepository<Screenshot, UUID>

I have a few query methods in there, but now I want to have another method that is not just a query. The method runs a query and if a record is found, it returns it, if not, it creates it with some default parameters. Where should this method go?

I saw custom repository implementations on the documentation, but because they are separate from the actual JpaRepository they don't seem to have access to the database.

Héctor
  • 24,444
  • 35
  • 132
  • 243
Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622

1 Answers1

1

Doing this the spring way you can create a service and Autowire your repository in that service and create your custom function in your service while using your repository to execute your queries

@Service
public class ScreenshotService{
    @Autowired
    private ScreenshotRepository screenshotRepository;


    public Boolean customMethod(){
        screenshotRepository.sampleQuery()
        //blah blah...
    }
.
.
.
Ayo K
  • 1,719
  • 2
  • 22
  • 34