1. 明确表和领域模型的设计顺序 应该是先设计领域模型再设计表 因为模型的一些属性出于安全性或者性能的考虑 可能会需要在数据库层面进行分开设计
2. 在mybatis-generator.xml里添加
<table tableName="item" domainObjectName="ItemDO" enableCountByExample="false"
enableDeleteByExample="false" enableUpdateByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false"/>
<table tableName="item_stock" domainObjectName="ItemStockDO" enableCountByExample="false"
enableDeleteByExample="false" enableUpdateByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false"/>
在生成的ItemDOMapper.xml和ItemStockDOMapper.xml中的selcet方法和insertSelective方法里添加属性
keyProperty="id" useGeneratedKeys="true"
3.创建ItemService接口
public interface ItemService {
//创建商品
ItemModel createItem(ItemModel itemModel) throws BusinessException;
//商品列表浏览
List<ItemModel> listItem();//查取所有商品信息
//商品详情浏览
ItemModel getItemById(Integer id);
//库存扣减
boolean decreaseStock(Integer itemId, Integer amount);
//商品销量增加
void increaseSales(Integer itemId, Integer amount) throws BusinessException;
}
浏览功能用get 对服务器不发生任何变化