加载一些测试数据
package com.mcf7.spring.domain;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
@Component
public class DatabaseLoader implements CommandLineRunner {
private final BookRepository repository;
@Autowired
public DatabaseLoader(BookRepository repository) {
this.repository = repository;
}
public void run(String... Strings) throws Exception {
Book book1 = new Book();
book1.setIsbn("6515616168418510");
book1.setTitle("SuperAwesomeTitle");
book1.setAuthor("MCF7");
book1.setDescription("This Book is super epic!");
repository.save(book1);
}
}
只是在理想情况下加载一些测试数据,这应该仅在开发配置文件下添加。