[Spring Data Repositories] learning notes -- define your own repository and springrepository
Sometimes, we need to use some of our own query methods, you can follow the steps below.
1. Define an interface containing this method
Interface UserRepositoryCustom {public void someCustomMethod(User user);}
2. Definition implementation
class UserRepositoryImpl implements UserRepositoryCustom {public void someCustomMethod(User user){//Your custom implementation}}
3. Define the repository you want to use
public interface UserRepository extends CrudRepository<User,Long>, UserRepositoryCustom {//Declare query methods here.}
4. There are two ways to configure repository
4.1 use a uniform suffix (the restriction is that your implementation must be configured with annotation and used only for autowired)
<Repositories base-package = "com. acme. repository "// The default suffix is Impl <repositories base-package =" com. acme. repository "repository-impl-postfix =" FooBar "/>
If no suffix is configured, The UserRepositoryImpl class is used by default.
4.2 define your own bean
<repositories base-package="com.acme.repository"/><beans:bean id="userRepositoryImpl" class="..."><!--further configuration--></beans:bean>
The above method can only be used for a single repository. If you want all repository to include this method, please refer to the next article.
I am using springmvc + spring data jpa; failed to convert the qgetResultList () TYPE OF THE EntityManager class.
Q. getResultList () is not necessarily a custom entity class. I remember a strong turn ..