1、引用依赖
<!--spring-data-jpa-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
2、加入JPA的相关配置
spring:
jpa:
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
show-sql: true
hibernate:
ddl-auto: none
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
最后一个是设置关联表的,默认情况下mysql的表名是区分大小写的,所有我们要在bean设置表名,但是单纯的加@Table(name = "HousingCaseColumn")没用,必须加上这个配置。
3、bean
import lombok.Data;
import javax.persistence.*;
@Data
@Entity
@Table(name = "HousingCaseColumn")
public class HousingCaseColumn {
@Id
@GeneratedValue
private Integer id;
@Column
private String cncolumn;
@Column
private String encolumn;
@Column
private String describe;
}
4、接口
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface HousingCaseColumnRepository extends JpaRepository<HousingCaseColumn, Integer> {
}
5、在启动器上加上扫描配置
@EnableJpaRepositories("com.repository")
@EntityScan("com..bean")
网友评论