E
E
Ening_apps2017-11-29 21:34:21
Java
Ening_apps, 2017-11-29 21:34:21

How to search in a database not by id in Spring Boot?

Good day, dear ones. There is this code:

@GetMapping("/notes/{id}")
    public ResponseEntity<Note> getNoteById(@PathVariable(value = "id") Long id) {
        Note note = noteRepository.findOne(id);
        if(note == null) {
            return ResponseEntity.notFound().build();
        }
        return ResponseEntity.ok().body(note);
    }

The method simply retrieves the entry with the given id from the database.
The noteRepository.findOne(id) method accepts either a Long or class extends org.springframework.data.domain.Example as input.
I want to search for information not by id , but by secretkey (String).
Please tell me how to do it.
Many thanks in advance for your replies!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirill Romanov, 2017-11-29
@Djaler

Create in noteRepository method
Node findBySecretKey(String secretKey);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question