CREATE TABLE product_category
(
category_id
int not null AUTO_INCREMENT,
category_name
varchar(64)not null comment’类目名字’,
category_type
decimal(8,2)not null comment’类目编号’,
create_time
timestamp not null default current_timestamp comment’创建时间’,
update_time
timestamp not null default current_timestamp on update current_timestamp
comment’修改时间’,
PRIMARY KEY (category_id
),
UNIQUE KEY une_category_type
(category_type
)
)comment’商品表’;
下图红色圈出来就是刚才新建的表。
mysql
mysql-connector-java
org.springframework.boot
spring-boot-starter-data-jpa
4.在resource目录下创建application.yml文件
用户名、密码、端口号可以改成自己的。
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
username: root
password: laomilaomilaomi
url: jdbc:mysql://localhost:3399/selldata?serverTimezone=UTC&characterEncoding=utf-8&useSSL=false
jpa:
show-sql: true
import javax.persistence.Entity;
import javax.persisten
ce.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
//类目
@Entity //表明是一个实体类
public class ProductCategory {
@Id //主键
@GeneratedValue(strategy = GenerationType.IDENTITY)//配置主键自增长
private Integer categoryId;//类目id
private String categoryName;//类目名字
private Integer categoryType;//类目编号
public Integer getCategoryId() {
return categoryId;
}
public void setCategoryId(Integer categoryId) {
this.categoryId = categoryId;
}
public String getCategoryName() {
return categoryName;
}
public void setCategoryName(String categoryName) {
this.categoryName = categoryName;
}
public Integer getCategoryType() {
return categoryType;
}
public void setCategoryType(Integer categoryType) {
this.categoryType = categoryType;
}
@Override
public String toString() {
return “ProductCategory{” +
“categoryId=” + categoryId +
“, categoryName='” + categoryName + ‘’’ +
“, categoryType=” + categoryType +
‘}’;
}
}
6.编写接口ProductCategoryRepository.java
import com.laomi.sell.dataobject.ProductCategory;
import org.springframework.data.jpa.repository.JpaRepository;
//https://blog.csdn.net/fly910905/article/details/78557110/ JpaRepository用法,实现增删改查
public interface ProductCategoryRepository extends JpaRepository<ProductCategory, Integer> {
}