注意的几点:java
spring.datasource.url = jdbc:mysql://localhost:3306/testcharacterEncoding=utf8&;useSSL=true 缘由:因为个人MySQL版本较高,如不加此配置,会报以下错误: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.mysql
import javax.persistence.Entity;spring
import javax.persistence.Id;sql
@Entityapp
public class Demo {ide
@Idui
private int id;this
private String name;url
private int age;.net
public long getId() { return id; }
public void setId(int id) { this.id = id; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public int getAge() { return age; }
public void setAge(int age) { this.age = age; }
缘由:这里是一个完整的entity类,目的是看上面import的包,在import包的时候,必定使用javax.persistence.*,不然将会出现错误,以下: org.hibernate.AnnotationException: No identifier specified for entity这个错误看上去是这张表没有主键,在使用hibernate的映射表的时候entity类是必需要主键的,不然就会报出这个异常。可是咱们已经配置了@ID,还会报这个错误是由于import错包了,错误的使用了org.springframework.data.annotation.Id包。