Spring Data - get last record from the table

k13i :

I'm using Spring Data JPA and I would like to retrieve the last record from Settings table.

I have SettingsRepository with standard methods implemented by Spring Data. How to write a method (or a query) to retrieve last row from the given table?

interface SettingsRepository extends JpaRepository<Settings, Long> {
    // ?
}
Lemmy :

You should use findTopByOrderByIdDesc()

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=36306&siteId=1