es 實戰

半窗殘陽發表於2020-10-31

@Document(indexName = "oooodin", type = "book")
public class Book {
    private Integer id;
    private String bookName;
    private String author;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getBookName() {
        return bookName;
    }

    public void setBookName(String bookName) {
        this.bookName = bookName;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    @Override
    public String toString() {
        return "Book{" +
                "id=" + id +
                ", bookName='" + bookName + '\'' +
                ", author='" + author + '\'' +
                '}';
    }
}

複製程式碼

import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;

public interface BookRepository extends ElasticsearchRepository<Book, Integer> {
}

  然後來測試一下看看(建立一個測試類):

複製程式碼

@RunWith(SpringRunner.class)
@SpringBootTest
public class RedisTest {

    @Autowired
    BookRepository bookRepository;

    @Test
    public void test01() {
        Book book = new Book();
        book.setId(1);
        book.setBookName("xxxx");
        book.setAuthor("yyyy");
        bookRepository.index(book);
    }

}

相關文章