记录一次SpringbootJpa的使用

  1. 刚开始maven导入springboot 1.5.30 失败,总以为maven的源不对,
    后来才知道应该格式符合的不对,所以1.5.3版本下载不下来。
    正确的是
    1.5.3.RELEASE

2.记录Jpa的使用记录
首先application.yml中写入
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
username: root
password: 123456 (有点要加’123456’才能识别,不过这里数字就好)
url: jdbc:mysql://localhost:3306/test?characterEncoding=utf-8&useSSL=false
3.新建一个Entity实体类

@Entity
public class ProductCategory {

        @Id
        @GeneratedValue
        private Integer categoryId;

        private String categoryName;

        private Integer categoryType;

@Entity表示实体类, @Id主键,@@GeneratedValue自增
Jpa自动做好表和实体类的映射关系,数据库表名是product_category,类名遵循驼峰式就好,规则的自动映射,如果数据库表名s_product_category,请加@Table(“s_product_category”)来配置映射关系.Jpa利用Hibennate,实现了基本的一些操作.

猜你喜欢

转载自blog.csdn.net/weixin_39137699/article/details/89490747