jpa简单demo调试druid


Druid连接池配置见https://www.cnblogs.com/blindjava/p/11504524.html

pom


mysql
mysql-connector-java
8.0.12


junit
junit
4.11
test

org.springframework.boot
spring-boot-starter-data-jpa


Entity
@Entity(name = "Customer")
public class Customer {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(length = 64)
private String name;
@Column(length = 64)
private String email;
@Column(length = 64)
private String address;
@Column(length = 11)
private String phone;

public Long getId() {
return id;
}

public void setId(Long 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;
}

public String getAddress() {
return address;
}

public void setAddress(String address) {
this.address = address;
}

public String getPhone() {
return phone;
}

public void setPhone(String phone) {
this.phone = phone;
}
}


Controller
@RestController
public class CustomerController {
@Autowired
CustomerRepository customerRepository;

@RequestMapping(value = "/save",method = RequestMethod.POST)
public void save(){
Customer customer = new Customer();
customer.setEmail("ggggggggg");
customerRepository.save(customer);
}
}
Repository层
@Repository
public interface CustomerRepository extends JpaRepository,Long> {
}
导包全为jax下
jpa底层使用Hibernate3自动建表