CREATE TABLE `merchant_purchase_stat` ( `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, `merchant_id` BIGINT UNSIGNED DEFAULT NULL COMMENT '商户ID,关联merchant主键', `goods_model` VARCHAR ( 300 ) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '基本库商品型号ID', `num` INT NOT NULL DEFAULT '0' COMMENT '数量', `stat_type` INT NOT NULL DEFAULT '0' COMMENT '统计类型,1、购买量 2、增长幅度', `market_date` date NOT NULL COMMENT '基本库商品上市时间(首发时间)', `stat_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '统计时间', PRIMARY KEY ( `id` ) USING BTREE, KEY `idx_merchant_id` ( `merchant_id` ) USING BTREE, KEY `idx_goods_model` ( `goods_model` ) USING BTREE ) ENGINE = INNODB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = DYNAMIC COMMENT = '店铺采购统计';根据表结构生成java实体类,持久层,业务层,添加注释,以及crud
时间: 2023-10-21 20:07:15 浏览: 72
根据表结构生成java实体类、持久层和业务层,添加注释以及CRUD操作的步骤如下:
1. 创建Java实体类MerchantPurchaseStat,包含以下属性:
```
public class MerchantPurchaseStat {
private Long id;
private Long merchantId;
private String goodsModel;
private Integer num;
private Integer statType;
private LocalDate marketDate;
private LocalDateTime statTime;
// getter and setter methods
}
```
2. 创建持久层接口MerchantPurchaseStatMapper,使用MyBatis框架进行数据访问:
```
@Mapper
public interface MerchantPurchaseStatMapper {
void insert(MerchantPurchaseStat stat);
void update(MerchantPurchaseStat stat);
void deleteById(Long id);
MerchantPurchaseStat findById(Long id);
List<MerchantPurchaseStat> findByMerchantId(Long merchantId);
List<MerchantPurchaseStat> findByGoodsModel(String goodsModel);
List<MerchantPurchaseStat> findByMarketDate(LocalDate marketDate);
}
```
3. 创建业务层接口MerchantPurchaseStatService,定义CRUD操作方法:
```
public interface MerchantPurchaseStatService {
void create(MerchantPurchaseStat stat);
void update(MerchantPurchaseStat stat);
void deleteById(Long id);
MerchantPurchaseStat findById(Long id);
List<MerchantPurchaseStat> findByMerchantId(Long merchantId);
List<MerchantPurchaseStat> findByGoodsModel(String goodsModel);
List<MerchantPurchaseStat> findByMarketDate(LocalDate marketDate);
}
```
4. 实现业务层接口MerchantPurchaseStatServiceImpl,调用持久层接口方法实现CRUD操作:
```
@Service
public class MerchantPurchaseStatServiceImpl implements MerchantPurchaseStatService {
@Autowired
private MerchantPurchaseStatMapper mapper;
@Override
public void create(MerchantPurchaseStat stat) {
mapper.insert(stat);
}
@Override
public void update(MerchantPurchaseStat stat) {
mapper.update(stat);
}
@Override
public void deleteById(Long id) {
mapper.deleteById(id);
}
@Override
public MerchantPurchaseStat findById(Long id) {
return mapper.findById(id);
}
@Override
public List<MerchantPurchaseStat> findByMerchantId(Long merchantId) {
return mapper.findByMerchantId(merchantId);
}
@Override
public List<MerchantPurchaseStat> findByGoodsModel(String goodsModel) {
return mapper.findByGoodsModel(goodsModel);
}
@Override
public List<MerchantPurchaseStat> findByMarketDate(LocalDate marketDate) {
return mapper.findByMarketDate(marketDate);
}
}
```
5. 在实体类和持久层接口中添加注释,描述类和方法的作用。
6. 在数据库中使用CRUD操作测试持久层和业务层的功能是否正常。
阅读全文