Add JPA to flyway sample
This commit is contained in:
@@ -16,17 +16,69 @@
|
||||
|
||||
package sample.flyway;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan
|
||||
@EnableAutoConfiguration
|
||||
public class SampleFlywayApplication {
|
||||
public class SampleFlywayApplication implements CommandLineRunner {
|
||||
|
||||
@Autowired
|
||||
private PersonRepository repository;
|
||||
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
System.err.println(repository.findAll());
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
SpringApplication.run(SampleFlywayApplication.class, args);
|
||||
}
|
||||
}
|
||||
|
||||
@Repository
|
||||
interface PersonRepository extends CrudRepository<Person, Long> {
|
||||
|
||||
}
|
||||
|
||||
@Entity
|
||||
class Person {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastname) {
|
||||
this.lastName = lastname;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Person [firstName=" + firstName + ", lastname=" + lastName
|
||||
+ "]";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user