parent
a17542421b
commit
8cd0741d6e
@ -1,23 +1,28 @@
|
||||
package com.example.demo;
|
||||
|
||||
import com.example.demo.Greeting;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@SpringBootApplication
|
||||
@RestController
|
||||
public class DemoApplication {
|
||||
@Autowired
|
||||
private PersonRepository personRepository;
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DemoApplication.class, args);
|
||||
}
|
||||
|
||||
@GetMapping("/hello")
|
||||
public Greeting hello() {
|
||||
return new Greeting(1, "hi");
|
||||
public String hello() {
|
||||
Person n = new Person();
|
||||
n.setName("bob");
|
||||
n.setEmail("bob@bob.com");
|
||||
personRepository.save(n);
|
||||
return "Saved";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,41 @@
|
||||
package com.example.demo;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
|
||||
@Entity // This tells Hibernate to make a table out of this class
|
||||
public class Person {
|
||||
@Id
|
||||
@GeneratedValue(strategy=GenerationType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String email;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
package com.example.demo;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
import com.example.demo.Person;
|
||||
|
||||
// This will be AUTO IMPLEMENTED by Spring into a Bean called userRepository
|
||||
// CRUD refers Create, Read, Update, Delete
|
||||
|
||||
public interface PersonRepository extends CrudRepository<Person, Integer> {
|
||||
|
||||
}
|
||||
@ -1 +1,2 @@
|
||||
|
||||
spring.jpa.hibernate.ddl-auto=update
|
||||
spring.datasource.url=jdbc:postgresql://localhost:5432/springdemo
|
||||
|
||||
Loading…
Reference in new issue