ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

基于Springboot微信点餐系统的开发与实现

2019-06-16 21:52:53  阅读:215  来源: 互联网

标签:comment varchar Springboot 微信 current timestamp 点餐 null id


微信点餐数据库注意事项

商品表:

1:在企业级中,由于数据量是比较大的,所以id一般采用的是varchar,不采用int

2:凡是涉及到价格的统一采用decimal,例如本项目中单价如下: product_price decimal(8,2) not null comment ‘单价’, 表示具有8位整数,以及两位小数,总共10位。

3:因为库存需要计算(加减),所以此处设置为int类型,商品表中库存如下:product_stock int not null comment ‘库存’,

4:商品图片,在数据库中一般以链接的形式存在,所以采用varchar类型(注意,在数据库中字段长度一般都是2的n次方):product_icon varchar(512) comment ‘小图’,

5:创建时间默认为当前时间: create_time timestamp not null default current_timestamp comment ‘创建时间’,

6:设置商品的状态:product_status tinyint(3) DEFAULT ‘0’ COMMENT ‘商品状态,0正常1下架’,

商品分类表:

1:因为商品分类是有限的,所以我这里直接采用int类型就已经足够了: category_id int not null auto_increment,

2:一般而言,均有创建时间和更新时间: 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)

订单表:

1:订单表和商品表的id都是一样的采用字符类型

2:订单状态一般都是比较少的,所以此处需要tinyint类型就可以了的: order_status tinyint(3) not null default ‘0’ comment ‘订单状态, 默认为新下单’,

3:支付状态和订单状态是一样的

4:订单表加索引: key idx_buyer_openid (buyer_openid)

订单详情表:

1:同上

具体数据库设计如下:

– 类目
create table product_category (
category_id int not null auto_increment,
category_name varchar(64) not null comment ‘类目名字’,
category_type int 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)
);

– 商品
create table product_info (
product_id varchar(32) not null,
product_name varchar(64) not null comment ‘商品名称’,
product_price decimal(8,2) not null comment ‘单价’,
product_stock int not null comment ‘库存’,
product_description varchar(64) comment ‘描述’,
product_icon varchar(512) comment ‘小图’,
product_status tinyint(3) DEFAULT ‘0’ COMMENT ‘商品状态,0正常1下架’,
category_type int 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 (product_id)
);

– 订单
create table order_master (
order_id varchar(32) not null,
buyer_name varchar(32) not null comment ‘买家名字’,
buyer_phone varchar(32) not null comment ‘买家电话’,
buyer_address varchar(128) not null comment ‘买家地址’,
buyer_openid varchar(64) not null comment ‘买家微信openid’,
order_amount decimal(8,2) not null comment ‘订单总金额’,
order_status tinyint(3) not null default ‘0’ comment ‘订单状态, 默认为新下单’,
pay_status tinyint(3) not null default ‘0’ 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 (order_id),
key idx_buyer_openid (buyer_openid)
);

– 订单商品
create table order_detail (
detail_id varchar(32) not null,
order_id varchar(32) not null,
product_id varchar(32) not null,
product_name varchar(64) not null comment ‘商品名称’,
product_price decimal(8,2) not null comment ‘当前价格,单位分’,
product_quantity int not null comment ‘数量’,
product_icon varchar(512) 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 (detail_id),
key idx_order_id (order_id)
);

– 卖家(登录后台使用, 卖家登录之后可能直接采用微信扫码登录,不使用账号密码)
create table seller_info (
id varchar(32) not null,
username varchar(32) not null,
password varchar(32) not null,
openid varchar(64) not null comment ‘微信openid’,
create_time timestamp not null default current_timestamp comment ‘创建时间’,
update_time timestamp not null default current_timestamp on update current_timestamp comment ‘修改时间’,
primary key (id)
) comment ‘卖家信息表’;

系统模块一:买家类目功能实现

1:ProductCategory类

注解@Entity是把数据库对象映射成属性;

@Id注解表示id是主键,@GeneratedValue表示主键id是自增类型;

@Data 注解在类上, 为类提供读写属性, 此外还提供了 equals()、hashCode()、toString() 方法等等,它用在springboot中可以减少一些步必要代码;需要在pom.xml里面进行配置依赖:

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
</dependency>

@DynamicUpdate注解表示的是更新变化的字段,而不是更新指定的字段。在Spring Data JPA 中要注意@DynamicInsert和@DynamicUpdate。

@DynamicInsert上设置为true表示insert对象的时候,生成动态的insert语句,如果这个字段的值是null就不会加入到insert语句当中,默认false。

@DynamicUpdate设置为true,表示的是update对象的时候,生成动态的update语句,如果这个字段的值是null就不会被加入到update语句中,默认false。比如说,我们修改了商品,那么系统中就会显示数据修改的时间。

补充:

1:注解

@Getter/@Setter : 注解在类上, 为类提供读写属性 @ToString : 注解在类上, 为类提供 toString() 方法
@Slf4j : 注解在类上, 为类提供一个属性名为 log 的 log4j 的日志对象
@Log4j : 注解在类上, 为类提供一个属性名为 log 的 log4j 的日志对象

2:SpringData JPA

(1)什么是SpringData JPA?

SpringData是一个用于简化数据库访问,支持云服务的开源框架。目标是使数据库访问变得方便快捷。公司的ORM框架,均采用SpringData JPA。SpringData是数据库开源框架,包含对关系数据库,非关系数据库,云数据服务访问支持等。

JPA的全称是Java Persistence API,Persistence 是持久化的意思。所以,中文全称是【JAVA对象持久化的 API】。简单来说,可以理解为是一种JAVA的标准规范,这个规范为JAVA对象的持久化制定了一些标准的接口。

要注意的是,JPA只是一个接口规范,而不是实现。具体实现由各供应商来完成,例如Hibernate,TopLink,OpenJPA都很好地实现了JPA接口。

(2)Hibernate和JPA的关系

JPA是Hibernate的一个抽象,提供 一些编程的API接口,但具体实现则由ORM厂商提供实现

(3)application.yml中配置jpa

jpa:
  #将数据库打印出来
  show-sql: true

表示将数据库给打印出来。

标签:comment,varchar,Springboot,微信,current,timestamp,点餐,null,id
来源: https://blog.csdn.net/qq_37606901/article/details/92429795

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有