简体   繁体   中英

Spring Repository Library Implementation Problem

I'm using Spring data JDBC library to implement my DAO. I"m very new to Spring Data Repository. Below is my error encounter.

@Repository
public class UserRepository extends CrudRepository<User, Integer> {}

Error : The type CrudRepository cannot be the superclass of UserRepository; a superclass must be a class

I'm using Spring Framework version 5.1.3 and spring-data-jdbc 1.0.3.

The CrudRepository provides sophisticated CRUD functionality for the entity class that is being managed.

 public interface CrudRepository<T, ID extends Serializable>
        extends Repository<T, ID> {

    <S extends T> S save(S entity);
    T findOne(ID primaryKey);
    Iterable<T> findAll();
    Long count();                                                                                                                   
    void delete(T entity);                                                                                                  
    boolean exists(ID primaryKey)
}
  • Saves the given entity.
  • Returns the entity identified by the given id.
  • Returns all entities.
  • Returns the number of entities.
  • Deletes the given entity.
  • Indicates whether an entity with the given id exists.

If you are looking for a simple query to get all data from you database just use Spring CrudRepository :

@Repository
public interface UserRepository extends CrudRepository<User, Integer> {
}

To get your data just use the method findAll already present in CrudRepository :

Iterable<User> users = userRepository.findAll();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM