Find by where NOT current row

jukenduit :

I am developing a small cms and I am using spring data jpa to do my database stuff.

When I add a new page, I want to make sure the slug doesn't already exist, for that purpose I added a method to my repository:

public interface PageRepository extends JpaRepository<Page, Integer> {

    Page findBySlug(String slug);

}

That works fine when adding.

However when editing a page, I want to check that the slug doesn't already exist but NOT for the current page, how can I do that? I guess I could somehow pass the current row id or something like that, but how would I do that?

marok :

You can write

Page findBySlugAndIdNot(String slug,Long id)

where id is name of your identifier in entity with proper type. Look at documentation

Guess you like

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