首页 > 解决方案 > Spring Data CrudRepository 类中的这个 S 参数是什么?

问题描述

谁能告诉我 org.springframework.data.repository 的 CrudRepository 接口中的 S 是什么?

我创建了一个名为“DBBooks”的类,它是我的数据库表“books”的支持对象。

DBBooks.java

SNIPPET 
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        @Column(name="book_index")
        private Integer book_index;
        public Integer getBook_index(){
            return book_index;
        }

我知道 T 是我的 DBBooks 对象,ID 是我表中的 book_index 键对象类型:

SNIPPET 
@Repository
public interface BookRepository extends CrudRepository<DBBook, Integer> {

}

SNIPPET 
@NoRepositoryBean
    public interface CrudRepository<T, ID> extends Repository<T, ID> {

        /**
         * Saves a given entity. Use the returned instance for further operations as the save operation might have changed the
         * entity instance completely.
         *
         * @param entity must not be {@literal null}.
         * @return the saved entity will never be {@literal null}.
         */
        <S extends T> S save(S entity);

        /**
         * Saves all given entities.
         *
         * @param entities must not be {@literal null}.
         * @return the saved entities will never be {@literal null}.
         * @throws IllegalArgumentException in case the given entity is {@literal null}.
         */
        <S extends T> Iterable<S> saveAll(Iterable<S> entities);

但是S是什么??我不明白。

标签: javadatabasespring-boot

解决方案


推荐阅读