-
-
Save iyengarajay/01e91a206df2b1016b20d2f1290f3860 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example; | |
import java.util.ArrayList; | |
import java.util.List; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.boot.CommandLineRunner; | |
import org.springframework.boot.SpringApplication; | |
import org.springframework.boot.autoconfigure.SpringBootApplication; | |
@SpringBootApplication | |
public class DemoApplication implements CommandLineRunner { | |
// Use constructor injection. | |
@Autowired | |
private EmployeeRepository employeeRepository; | |
public static void main(String[] args) { | |
SpringApplication.run(DemoApplication.class, args); | |
} | |
// Initialization to add data to h2 db. | |
@Override | |
public void run(String... args) throws Exception { | |
List<Employee> employees = getAllEmployees(); | |
employees.forEach(employee -> employeeRepository.save(employee)); | |
} | |
private List<Employee> getAllEmployees() { | |
List<Employee> employees = new ArrayList<>(); | |
employees.add(new Employee("Barney", "Stinson")); | |
employees.add(new Employee("Alex", "Hitch")); | |
employees.add(new Employee("Douglas", "Ramsey")); | |
return employees; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment