定义商品类goods包含单价unitprice_MyBatis+Spring技术整合实现商品模块CRUD操作

业务描述

基于Spring,MyBatis,SpringBoot,Thymeleaf技术实现商品模块的增删改查操作。

项目环境初始化

准备工作

1. MySQL(5.7)2. JDK (1.8)3. Maven (3.6.3)4. STS(4.7.1)

数据库初始化

打开mysql控制台,然后按如下步骤执行goods.sql文件。
第一步:登录mysql。

mysql –uroot –proot

第二步:设置控制台编码方式。

set names utf8;

第三步:执行goods.sql文件(切记不要打开文件复制到mysql客户端运行)。

source d:/goods.sql

其中goods.sql文件内容如下:

drop database if exists dbgoods;create database dbgoods default character set utf8;use dbgoods;create table tb_goods(     id bigint primary key auto_increment,     name varchar(100) not null,     remark text,     createdTime datetime not null)engine=InnoDB;insert into tb_goods values (null,'java','very good',now());insert into tb_goods values (null,'mysql','RDBMS',now());insert into tb_goods values (null,'Oracle','RDBMS',now());insert into tb_goods values (null,'java','very good',now());insert into tb_goods values (null,'mysql','RDBMS',now());insert into tb_goods values (null,'Oracle','RDBMS',now());insert into tb_goods values (null,'java','very good',now());

创建项目并添加依赖

第一步:基于start.spring.io 创建项目并设置基本信息

ef9a89e1f4994ae67744ba6b0b03c39e.png

第二步:创建项目时指定项目核心依赖

6d0e09b7a37983d3cb6cb3ee017f8834.png

第三步:项目创建以后分析其结构

044676b3aaec4adebb1a51d298c96a04.png

项目配置文件内容初始化

#serverserver.port=80#server.servlet.context-path=/#spring datasourcespring.datasource.url=jdbc:mysql:///dbgoods?serverTimezone=GMT%2B8&characterEncoding=utf8spring.datasource.username=rootspring.datasource.password=root#spring mybatismybatis.mapper-locations=classpath:/mapper/*/*.xml#spring logginglogging.level.com.cy=debug#spring thymeleafspring.thymeleaf.prefix=classpath:/templates/pages/spring.thymeleaf.suffix=.htmlspring.thymeleaf.cache=false

项目API架构设计

其API架构设计,如图所示:

203df2d9c87a0de50e11f7868a4d4c0d.png

商品查询业务实现

业务描述

从商品库查询商品信息,并将商品信息呈现在页面上,如图所示:

206d5de5f188a4a43b0124375e6dd531.png

业务时序分析

查询所有商品信息,其业务时序分析,如图所示:

cf852e7742dfa1c55b3cac9fb6df1513.png

Pojo类定义

定义Goods对象,用于封装从数据库查询到的商品信息。

package com.cy.pj.goods.pojo;import java.util.Date;public class Goods {    private Long id;//id bigint primary key auto_increment    private String name;//name varchar(100) not null    private String remark;//remark text    private Date createdTime;//createdTime datetime    public Long getId() {        return id;    }    public void setId(Long id) {        this.id = id;    }    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }    public String getRemark() {        return remark;    }    public void setRemark(String remark) {        this.remark = remark;    }    public Date getCreatedTime() {
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
/* MySQL Data Transfer Source Host: 115.29.41.210 Source Database: micromall Target Host: 115.29.41.210 Target Database: micromall Date: 2015/6/7 15:57:30 */ SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- -- Table structure for wsc_sales_goods_msg -- ---------------------------- CREATE TABLE `wsc_sales_goods_msg` ( `sales_id` int(11) NOT NULL AUTO_INCREMENT, `goods_id` int(11) DEFAULT NULL COMMENT '商品id', `sales_num` int(11) DEFAULT NULL COMMENT '销售的数量', `back_num` int(11) DEFAULT NULL COMMENT '退货数量', `sales_money` double DEFAULT NULL COMMENT '商品售销金额小计', `back_money` double DEFAULT NULL COMMENT '商品退货金额小计', `order_id` int(11) DEFAULT NULL COMMENT '商品对应的订单', `state` int(11) DEFAULT NULL COMMENT '3-已正常交易完成', `time` datetime DEFAULT NULL COMMENT '订单完成时间', `user_id` int(11) DEFAULT NULL COMMENT '会员', `user_name` varchar(255) DEFAULT NULL, `goods_name` varchar(255) DEFAULT NULL, `buying_price` double(11,0) DEFAULT '0' COMMENT '商品进', `barcode` varchar(255) DEFAULT NULL COMMENT '形码条', `goods_price` double(11,0) DEFAULT NULL COMMENT '商品', `profit` double(11,0) DEFAULT NULL COMMENT '每件商品的利润', PRIMARY KEY (`sales_id`) ) ENGINE=InnoDB AUTO_INCREMENT=30 DEFAULT CHARSET=utf8; -- ---------------------------- -- Records -- ---------------------------- INSERT INTO `wsc_sales_goods_msg` VALUES ('27', '148', '1', '0', '0.01', '0', '19', '3', '2015-06-07 14:15:04', '8', '顾明轩', '德芙心随巧克力90g单包', '12', '5555555', '0', '-12'); INSERT INTO `wsc_sales_goods_msg` VALUES ('28', '148', '1', '0', '0.01', '0', '18', '3', '2015-06-07 14:12:59', '8', '顾明轩', '德芙心随巧克力90g单包', '12', '5555555', '0', '-12'); INSERT INTO `wsc_sales_goods_msg` VALUES ('29', '148', '1', '0', '0.01', '0', '14', '3', '2015-06-07 10:26:45', '8', '顾明轩', '德芙心随巧克力90g单包', '12', '5555555', '0', '-12');
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值