Pergunta

I am using Spring data rest and I want to add some additional functionality to my repository.

@RestResource(exported = true)
public class ItemRepository extends JpaRepository<Item, Long> {

    @Query("update ...")
    void modifyItem();
}

The modifyItem() method can only be accessed through a GET request at /items/find/modifyItem

How can I change the requestmethod to UPDATE?

How can I remove the "find" from the URI?

Foi útil?

Solução

Two issues here:

  1. The query method declaration is invalid as it needs to carry an @Modifying annotation to correctly execute the query.
  2. The method is not exported by Spring Data REST as it's generally hard to reason about the correct HTTP method to use for the exposure. The current way of exposing the method is to plug in a manually implemented controller that gets the repository injected and manually invokes the method.

Outras dicas

@Query(Update (Table name) SET (schema you want to update) = :variable WHERE ID=1)
public void update(@Param("variable") String variable);

I think that should work

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top