Consider a Spring Data Jpa Repository:
public interface UserRepository extends JpaRepository<User, Long> {
User findOneByDeletedIsFalseAndActivationKey(String activationKey);
List<User> findAllByDeletedIsFalseAndActivatedIsFalseAndCreatedDateBefore(DateTime dateTime);
User findOneByDeletedIsFalseAndLogin(String login);
User findOneByDeletedIsFalseAndEmail(String email);
}
Notice each method has "DeletedIsFalse
" in it. Is there a simple way to make method names shorter? Like i.e.:
@FullMethodName("findOneByDeletedIsFalseAndEmail")
User findOneByEmail(String email);
Use
default
Java 8 feature for wrapping, just like so:See an example.
Now you can use Java 8
default
interface methods as @Maksim Kostromin described. But there is no such a feature in Spring.-- Old answer
There is no such a way. You can specify any name for a method and add an annotation
@Query
with parameter value which holds desired query to database like this:or, with native sql query:
You can also use names that follow the naming convention for queries since
@Query
annotation will take precedence over query from method name.@Query docs
Upd:
from Spring docs: