Spring Link to a custom REST data method

I have Spring Data Warehouses subject to REST with @RepositoryRestMvcConfiguration. The problem is that custom methods do not seem to display by default, and I don't see annotations for setting it up. My code is:

@RepositoryRestResource(path = "users", collectionResourceRel = "users")
public interface UserRepository extends JpaRepository<User, Integer> {

@Modifying
@Query("update User u set u.password = ?3 where u.login = ?1 and u.password = ?2")
int changePassword(String login, String oldPassword, String newPassword);

User findUserByEmail(String email);

User findUserByLogin(String login);

}

I need a REST URL for changePassword, preferably with how to configure it somehow like in the controller:

@Modifying
@Query("update User u set u.password = ?3 where u.login = ?1 and u.password = ?2")
@RepositoryRestRequestMapping(value={"/changepwd"},  method = RequestMethod.POST)
int changePassword(String login, String oldPassword, String newPassword);

Well, it’s clear that the repository class is not REST aware and this is probably the wrong place for the annotation associated with the website. But some way to configure it must exist. It is too bad to add controllers for such needs - in fact, several operations against the same class of entities that do not exactly correspond to the CRUD concept.

Spring Data - . , - , .

+4

Source: https://habr.com/ru/post/1542670/


All Articles