java实现商品的分类_Spring 商品分类

本文展示了如何使用Java和Spring框架实现商品分类管理。通过定义实体类`Goods`和`Classification`,并利用JPA的注解进行数据库映射,实现商品与分类的多对一关系。此外,还通过`GoodsRepository`和`ClassificationRepository`接口进行数据库操作,最后在驱动类中创建示例数据完成商品分类的增删改查。
摘要由CSDN通过智能技术生成

实体商品示例代码

package cn.maxhou.entity;

import java.io.Serializable;

import java.math.BigDecimal;

import javax.persistence.Entity;

import javax.persistence.GeneratedValue;

import javax.persistence.GenerationType;

import javax.persistence.Id;

import javax.persistence.JoinColumn;

import javax.persistence.ManyToOne;

@Entity//该注解表名该类为一个实体

public class Goods implements Serializable {

private static final long serialVersionUID = 5060150518287868308L;

@Id//id注解

@GeneratedValue(strategy=GenerationType.IDENTITY)//ID自增注解

private int id;

private String name;

private String specifications;

private BigDecimal price;

private int quantity;

@ManyToOne//表名商品和分类的关系是多对一

@JoinColumn(name = "classification_id")//设置加入类名

private Classification classification;

public Goods() {

}

public Goods(String name, String specifications, BigDecimal price, int quantity) {

super();

this.name = name;

this.specifications = specifications;

this.price = price;

this.quantity = quan

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值