慕课秒杀项目(基于SSM)
- github代码
- 秒杀业务分析
- DAO层设计与开发
- 数据库设计
- DAO实体与接口编码
- 基于myBatis实现DAO
- myBatis整合Spring编码
- Service层
- Web层
- 设计Restful接口
- 整合配置SpringMVC框架
github代码
github代码:慕课网seckill
秒杀业务分析
#mermaid-svg-SHalStM6g5F69q4t .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-SHalStM6g5F69q4t .label text{fill:#333}#mermaid-svg-SHalStM6g5F69q4t .node rect,#mermaid-svg-SHalStM6g5F69q4t .node circle,#mermaid-svg-SHalStM6g5F69q4t .node ellipse,#mermaid-svg-SHalStM6g5F69q4t .node polygon,#mermaid-svg-SHalStM6g5F69q4t .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-SHalStM6g5F69q4t .node .label{text-align:center;fill:#333}#mermaid-svg-SHalStM6g5F69q4t .node.clickable{cursor:pointer}#mermaid-svg-SHalStM6g5F69q4t .arrowheadPath{fill:#333}#mermaid-svg-SHalStM6g5F69q4t .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-SHalStM6g5F69q4t .flowchart-link{stroke:#333;fill:none}#mermaid-svg-SHalStM6g5F69q4t .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-SHalStM6g5F69q4t .edgeLabel rect{opacity:0.9}#mermaid-svg-SHalStM6g5F69q4t .edgeLabel span{color:#333}#mermaid-svg-SHalStM6g5F69q4t .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-SHalStM6g5F69q4t .cluster text{fill:#333}#mermaid-svg-SHalStM6g5F69q4t div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-SHalStM6g5F69q4t .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-SHalStM6g5F69q4t text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-SHalStM6g5F69q4t .actor-line{stroke:grey}#mermaid-svg-SHalStM6g5F69q4t .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-SHalStM6g5F69q4t .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-SHalStM6g5F69q4t #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-SHalStM6g5F69q4t .sequenceNumber{fill:#fff}#mermaid-svg-SHalStM6g5F69q4t #sequencenumber{fill:#333}#mermaid-svg-SHalStM6g5F69q4t #crosshead path{fill:#333;stroke:#333}#mermaid-svg-SHalStM6g5F69q4t .messageText{fill:#333;stroke:#333}#mermaid-svg-SHalStM6g5F69q4t .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-SHalStM6g5F69q4t .labelText,#mermaid-svg-SHalStM6g5F69q4t .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-SHalStM6g5F69q4t .loopText,#mermaid-svg-SHalStM6g5F69q4t .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-SHalStM6g5F69q4t .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-SHalStM6g5F69q4t .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-SHalStM6g5F69q4t .noteText,#mermaid-svg-SHalStM6g5F69q4t .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-SHalStM6g5F69q4t .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-SHalStM6g5F69q4t .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-SHalStM6g5F69q4t .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-SHalStM6g5F69q4t .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-SHalStM6g5F69q4t .section{stroke:none;opacity:0.2}#mermaid-svg-SHalStM6g5F69q4t .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-SHalStM6g5F69q4t .section2{fill:#fff400}#mermaid-svg-SHalStM6g5F69q4t .section1,#mermaid-svg-SHalStM6g5F69q4t .section3{fill:#fff;opacity:0.2}#mermaid-svg-SHalStM6g5F69q4t .sectionTitle0{fill:#333}#mermaid-svg-SHalStM6g5F69q4t .sectionTitle1{fill:#333}#mermaid-svg-SHalStM6g5F69q4t .sectionTitle2{fill:#333}#mermaid-svg-SHalStM6g5F69q4t .sectionTitle3{fill:#333}#mermaid-svg-SHalStM6g5F69q4t .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-SHalStM6g5F69q4t .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-SHalStM6g5F69q4t .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-SHalStM6g5F69q4t .grid path{stroke-width:0}#mermaid-svg-SHalStM6g5F69q4t .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-SHalStM6g5F69q4t .task{stroke-width:2}#mermaid-svg-SHalStM6g5F69q4t .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-SHalStM6g5F69q4t .taskText:not([font-size]){font-size:11px}#mermaid-svg-SHalStM6g5F69q4t .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-SHalStM6g5F69q4t .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-SHalStM6g5F69q4t .task.clickable{cursor:pointer}#mermaid-svg-SHalStM6g5F69q4t .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-SHalStM6g5F69q4t .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-SHalStM6g5F69q4t .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-SHalStM6g5F69q4t .taskText0,#mermaid-svg-SHalStM6g5F69q4t .taskText1,#mermaid-svg-SHalStM6g5F69q4t .taskText2,#mermaid-svg-SHalStM6g5F69q4t .taskText3{fill:#fff}#mermaid-svg-SHalStM6g5F69q4t .task0,#mermaid-svg-SHalStM6g5F69q4t .task1,#mermaid-svg-SHalStM6g5F69q4t .task2,#mermaid-svg-SHalStM6g5F69q4t .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-SHalStM6g5F69q4t .taskTextOutside0,#mermaid-svg-SHalStM6g5F69q4t .taskTextOutside2{fill:#000}#mermaid-svg-SHalStM6g5F69q4t .taskTextOutside1,#mermaid-svg-SHalStM6g5F69q4t .taskTextOutside3{fill:#000}#mermaid-svg-SHalStM6g5F69q4t .active0,#mermaid-svg-SHalStM6g5F69q4t .active1,#mermaid-svg-SHalStM6g5F69q4t .active2,#mermaid-svg-SHalStM6g5F69q4t .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-SHalStM6g5F69q4t .activeText0,#mermaid-svg-SHalStM6g5F69q4t .activeText1,#mermaid-svg-SHalStM6g5F69q4t .activeText2,#mermaid-svg-SHalStM6g5F69q4t .activeText3{fill:#000 !important}#mermaid-svg-SHalStM6g5F69q4t .done0,#mermaid-svg-SHalStM6g5F69q4t .done1,#mermaid-svg-SHalStM6g5F69q4t .done2,#mermaid-svg-SHalStM6g5F69q4t .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-SHalStM6g5F69q4t .doneText0,#mermaid-svg-SHalStM6g5F69q4t .doneText1,#mermaid-svg-SHalStM6g5F69q4t .doneText2,#mermaid-svg-SHalStM6g5F69q4t .doneText3{fill:#000 !important}#mermaid-svg-SHalStM6g5F69q4t .crit0,#mermaid-svg-SHalStM6g5F69q4t .crit1,#mermaid-svg-SHalStM6g5F69q4t .crit2,#mermaid-svg-SHalStM6g5F69q4t .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-SHalStM6g5F69q4t .activeCrit0,#mermaid-svg-SHalStM6g5F69q4t .activeCrit1,#mermaid-svg-SHalStM6g5F69q4t .activeCrit2,#mermaid-svg-SHalStM6g5F69q4t .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-SHalStM6g5F69q4t .doneCrit0,#mermaid-svg-SHalStM6g5F69q4t .doneCrit1,#mermaid-svg-SHalStM6g5F69q4t .doneCrit2,#mermaid-svg-SHalStM6g5F69q4t .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-SHalStM6g5F69q4t .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-SHalStM6g5F69q4t .milestoneText{font-style:italic}#mermaid-svg-SHalStM6g5F69q4t .doneCritText0,#mermaid-svg-SHalStM6g5F69q4t .doneCritText1,#mermaid-svg-SHalStM6g5F69q4t .doneCritText2,#mermaid-svg-SHalStM6g5F69q4t .doneCritText3{fill:#000 !important}#mermaid-svg-SHalStM6g5F69q4t .activeCritText0,#mermaid-svg-SHalStM6g5F69q4t .activeCritText1,#mermaid-svg-SHalStM6g5F69q4t .activeCritText2,#mermaid-svg-SHalStM6g5F69q4t .activeCritText3{fill:#000 !important}#mermaid-svg-SHalStM6g5F69q4t .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-SHalStM6g5F69q4t g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-SHalStM6g5F69q4t g.classGroup text .title{font-weight:bolder}#mermaid-svg-SHalStM6g5F69q4t g.clickable{cursor:pointer}#mermaid-svg-SHalStM6g5F69q4t g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-SHalStM6g5F69q4t g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-SHalStM6g5F69q4t .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-SHalStM6g5F69q4t .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-SHalStM6g5F69q4t .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-SHalStM6g5F69q4t .dashed-line{stroke-dasharray:3}#mermaid-svg-SHalStM6g5F69q4t #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-SHalStM6g5F69q4t #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-SHalStM6g5F69q4t #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-SHalStM6g5F69q4t #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-SHalStM6g5F69q4t #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-SHalStM6g5F69q4t #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-SHalStM6g5F69q4t #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-SHalStM6g5F69q4t #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-SHalStM6g5F69q4t .commit-id,#mermaid-svg-SHalStM6g5F69q4t .commit-msg,#mermaid-svg-SHalStM6g5F69q4t .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-SHalStM6g5F69q4t .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-SHalStM6g5F69q4t .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-SHalStM6g5F69q4t g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-SHalStM6g5F69q4t g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-SHalStM6g5F69q4t g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-SHalStM6g5F69q4t g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-SHalStM6g5F69q4t g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-SHalStM6g5F69q4t g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-SHalStM6g5F69q4t .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-SHalStM6g5F69q4t .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-SHalStM6g5F69q4t .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-SHalStM6g5F69q4t .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-SHalStM6g5F69q4t .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-SHalStM6g5F69q4t .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-SHalStM6g5F69q4t .edgeLabel text{fill:#333}#mermaid-svg-SHalStM6g5F69q4t .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-SHalStM6g5F69q4t .node circle.state-start{fill:black;stroke:black}#mermaid-svg-SHalStM6g5F69q4t .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-SHalStM6g5F69q4t #statediagram-barbEnd{fill:#9370db}#mermaid-svg-SHalStM6g5F69q4t .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-SHalStM6g5F69q4t .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-SHalStM6g5F69q4t .statediagram-state .divider{stroke:#9370db}#mermaid-svg-SHalStM6g5F69q4t .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-SHalStM6g5F69q4t .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-SHalStM6g5F69q4t .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-SHalStM6g5F69q4t .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-SHalStM6g5F69q4t .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-SHalStM6g5F69q4t .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-SHalStM6g5F69q4t .note-edge{stroke-dasharray:5}#mermaid-svg-SHalStM6g5F69q4t .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-SHalStM6g5F69q4t .error-icon{fill:#522}#mermaid-svg-SHalStM6g5F69q4t .error-text{fill:#522;stroke:#522}#mermaid-svg-SHalStM6g5F69q4t .edge-thickness-normal{stroke-width:2px}#mermaid-svg-SHalStM6g5F69q4t .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-SHalStM6g5F69q4t .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-SHalStM6g5F69q4t .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-SHalStM6g5F69q4t .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-SHalStM6g5F69q4t .marker{fill:#333}#mermaid-svg-SHalStM6g5F69q4t .marker.cross{stroke:#333}:root { --mermaid-font-family: "trebuchet ms", verdana, arial;}#mermaid-svg-SHalStM6g5F69q4t {color: rgba(0, 0, 0, 0.75);font: ;}
添加/调整
秒杀/预售
付款/退货
发货/核账
商家
库存
用户
秒杀业务核心是对库存的处理。
用户针对库存业务分析:
#mermaid-svg-WYhY6Mfad6W6NDOs .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-WYhY6Mfad6W6NDOs .label text{fill:#333}#mermaid-svg-WYhY6Mfad6W6NDOs .node rect,#mermaid-svg-WYhY6Mfad6W6NDOs .node circle,#mermaid-svg-WYhY6Mfad6W6NDOs .node ellipse,#mermaid-svg-WYhY6Mfad6W6NDOs .node polygon,#mermaid-svg-WYhY6Mfad6W6NDOs .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-WYhY6Mfad6W6NDOs .node .label{text-align:center;fill:#333}#mermaid-svg-WYhY6Mfad6W6NDOs .node.clickable{cursor:pointer}#mermaid-svg-WYhY6Mfad6W6NDOs .arrowheadPath{fill:#333}#mermaid-svg-WYhY6Mfad6W6NDOs .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-WYhY6Mfad6W6NDOs .flowchart-link{stroke:#333;fill:none}#mermaid-svg-WYhY6Mfad6W6NDOs .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-WYhY6Mfad6W6NDOs .edgeLabel rect{opacity:0.9}#mermaid-svg-WYhY6Mfad6W6NDOs .edgeLabel span{color:#333}#mermaid-svg-WYhY6Mfad6W6NDOs .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-WYhY6Mfad6W6NDOs .cluster text{fill:#333}#mermaid-svg-WYhY6Mfad6W6NDOs div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-WYhY6Mfad6W6NDOs .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-WYhY6Mfad6W6NDOs text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-WYhY6Mfad6W6NDOs .actor-line{stroke:grey}#mermaid-svg-WYhY6Mfad6W6NDOs .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-WYhY6Mfad6W6NDOs .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-WYhY6Mfad6W6NDOs #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-WYhY6Mfad6W6NDOs .sequenceNumber{fill:#fff}#mermaid-svg-WYhY6Mfad6W6NDOs #sequencenumber{fill:#333}#mermaid-svg-WYhY6Mfad6W6NDOs #crosshead path{fill:#333;stroke:#333}#mermaid-svg-WYhY6Mfad6W6NDOs .messageText{fill:#333;stroke:#333}#mermaid-svg-WYhY6Mfad6W6NDOs .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-WYhY6Mfad6W6NDOs .labelText,#mermaid-svg-WYhY6Mfad6W6NDOs .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-WYhY6Mfad6W6NDOs .loopText,#mermaid-svg-WYhY6Mfad6W6NDOs .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-WYhY6Mfad6W6NDOs .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-WYhY6Mfad6W6NDOs .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-WYhY6Mfad6W6NDOs .noteText,#mermaid-svg-WYhY6Mfad6W6NDOs .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-WYhY6Mfad6W6NDOs .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-WYhY6Mfad6W6NDOs .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-WYhY6Mfad6W6NDOs .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-WYhY6Mfad6W6NDOs .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-WYhY6Mfad6W6NDOs .section{stroke:none;opacity:0.2}#mermaid-svg-WYhY6Mfad6W6NDOs .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-WYhY6Mfad6W6NDOs .section2{fill:#fff400}#mermaid-svg-WYhY6Mfad6W6NDOs .section1,#mermaid-svg-WYhY6Mfad6W6NDOs .section3{fill:#fff;opacity:0.2}#mermaid-svg-WYhY6Mfad6W6NDOs .sectionTitle0{fill:#333}#mermaid-svg-WYhY6Mfad6W6NDOs .sectionTitle1{fill:#333}#mermaid-svg-WYhY6Mfad6W6NDOs .sectionTitle2{fill:#333}#mermaid-svg-WYhY6Mfad6W6NDOs .sectionTitle3{fill:#333}#mermaid-svg-WYhY6Mfad6W6NDOs .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-WYhY6Mfad6W6NDOs .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-WYhY6Mfad6W6NDOs .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-WYhY6Mfad6W6NDOs .grid path{stroke-width:0}#mermaid-svg-WYhY6Mfad6W6NDOs .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-WYhY6Mfad6W6NDOs .task{stroke-width:2}#mermaid-svg-WYhY6Mfad6W6NDOs .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-WYhY6Mfad6W6NDOs .taskText:not([font-size]){font-size:11px}#mermaid-svg-WYhY6Mfad6W6NDOs .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-WYhY6Mfad6W6NDOs .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-WYhY6Mfad6W6NDOs .task.clickable{cursor:pointer}#mermaid-svg-WYhY6Mfad6W6NDOs .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-WYhY6Mfad6W6NDOs .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-WYhY6Mfad6W6NDOs .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-WYhY6Mfad6W6NDOs .taskText0,#mermaid-svg-WYhY6Mfad6W6NDOs .taskText1,#mermaid-svg-WYhY6Mfad6W6NDOs .taskText2,#mermaid-svg-WYhY6Mfad6W6NDOs .taskText3{fill:#fff}#mermaid-svg-WYhY6Mfad6W6NDOs .task0,#mermaid-svg-WYhY6Mfad6W6NDOs .task1,#mermaid-svg-WYhY6Mfad6W6NDOs .task2,#mermaid-svg-WYhY6Mfad6W6NDOs .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-WYhY6Mfad6W6NDOs .taskTextOutside0,#mermaid-svg-WYhY6Mfad6W6NDOs .taskTextOutside2{fill:#000}#mermaid-svg-WYhY6Mfad6W6NDOs .taskTextOutside1,#mermaid-svg-WYhY6Mfad6W6NDOs .taskTextOutside3{fill:#000}#mermaid-svg-WYhY6Mfad6W6NDOs .active0,#mermaid-svg-WYhY6Mfad6W6NDOs .active1,#mermaid-svg-WYhY6Mfad6W6NDOs .active2,#mermaid-svg-WYhY6Mfad6W6NDOs .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-WYhY6Mfad6W6NDOs .activeText0,#mermaid-svg-WYhY6Mfad6W6NDOs .activeText1,#mermaid-svg-WYhY6Mfad6W6NDOs .activeText2,#mermaid-svg-WYhY6Mfad6W6NDOs .activeText3{fill:#000 !important}#mermaid-svg-WYhY6Mfad6W6NDOs .done0,#mermaid-svg-WYhY6Mfad6W6NDOs .done1,#mermaid-svg-WYhY6Mfad6W6NDOs .done2,#mermaid-svg-WYhY6Mfad6W6NDOs .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-WYhY6Mfad6W6NDOs .doneText0,#mermaid-svg-WYhY6Mfad6W6NDOs .doneText1,#mermaid-svg-WYhY6Mfad6W6NDOs .doneText2,#mermaid-svg-WYhY6Mfad6W6NDOs .doneText3{fill:#000 !important}#mermaid-svg-WYhY6Mfad6W6NDOs .crit0,#mermaid-svg-WYhY6Mfad6W6NDOs .crit1,#mermaid-svg-WYhY6Mfad6W6NDOs .crit2,#mermaid-svg-WYhY6Mfad6W6NDOs .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-WYhY6Mfad6W6NDOs .activeCrit0,#mermaid-svg-WYhY6Mfad6W6NDOs .activeCrit1,#mermaid-svg-WYhY6Mfad6W6NDOs .activeCrit2,#mermaid-svg-WYhY6Mfad6W6NDOs .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-WYhY6Mfad6W6NDOs .doneCrit0,#mermaid-svg-WYhY6Mfad6W6NDOs .doneCrit1,#mermaid-svg-WYhY6Mfad6W6NDOs .doneCrit2,#mermaid-svg-WYhY6Mfad6W6NDOs .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-WYhY6Mfad6W6NDOs .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-WYhY6Mfad6W6NDOs .milestoneText{font-style:italic}#mermaid-svg-WYhY6Mfad6W6NDOs .doneCritText0,#mermaid-svg-WYhY6Mfad6W6NDOs .doneCritText1,#mermaid-svg-WYhY6Mfad6W6NDOs .doneCritText2,#mermaid-svg-WYhY6Mfad6W6NDOs .doneCritText3{fill:#000 !important}#mermaid-svg-WYhY6Mfad6W6NDOs .activeCritText0,#mermaid-svg-WYhY6Mfad6W6NDOs .activeCritText1,#mermaid-svg-WYhY6Mfad6W6NDOs .activeCritText2,#mermaid-svg-WYhY6Mfad6W6NDOs .activeCritText3{fill:#000 !important}#mermaid-svg-WYhY6Mfad6W6NDOs .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-WYhY6Mfad6W6NDOs g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-WYhY6Mfad6W6NDOs g.classGroup text .title{font-weight:bolder}#mermaid-svg-WYhY6Mfad6W6NDOs g.clickable{cursor:pointer}#mermaid-svg-WYhY6Mfad6W6NDOs g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-WYhY6Mfad6W6NDOs g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-WYhY6Mfad6W6NDOs .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-WYhY6Mfad6W6NDOs .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-WYhY6Mfad6W6NDOs .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-WYhY6Mfad6W6NDOs .dashed-line{stroke-dasharray:3}#mermaid-svg-WYhY6Mfad6W6NDOs #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-WYhY6Mfad6W6NDOs #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-WYhY6Mfad6W6NDOs #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-WYhY6Mfad6W6NDOs #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-WYhY6Mfad6W6NDOs #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-WYhY6Mfad6W6NDOs #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-WYhY6Mfad6W6NDOs #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-WYhY6Mfad6W6NDOs #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-WYhY6Mfad6W6NDOs .commit-id,#mermaid-svg-WYhY6Mfad6W6NDOs .commit-msg,#mermaid-svg-WYhY6Mfad6W6NDOs .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-WYhY6Mfad6W6NDOs .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-WYhY6Mfad6W6NDOs .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-WYhY6Mfad6W6NDOs g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-WYhY6Mfad6W6NDOs g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-WYhY6Mfad6W6NDOs g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-WYhY6Mfad6W6NDOs g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-WYhY6Mfad6W6NDOs g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-WYhY6Mfad6W6NDOs g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-WYhY6Mfad6W6NDOs .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-WYhY6Mfad6W6NDOs .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-WYhY6Mfad6W6NDOs .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-WYhY6Mfad6W6NDOs .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-WYhY6Mfad6W6NDOs .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-WYhY6Mfad6W6NDOs .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-WYhY6Mfad6W6NDOs .edgeLabel text{fill:#333}#mermaid-svg-WYhY6Mfad6W6NDOs .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-WYhY6Mfad6W6NDOs .node circle.state-start{fill:black;stroke:black}#mermaid-svg-WYhY6Mfad6W6NDOs .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-WYhY6Mfad6W6NDOs #statediagram-barbEnd{fill:#9370db}#mermaid-svg-WYhY6Mfad6W6NDOs .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-WYhY6Mfad6W6NDOs .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-WYhY6Mfad6W6NDOs .statediagram-state .divider{stroke:#9370db}#mermaid-svg-WYhY6Mfad6W6NDOs .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-WYhY6Mfad6W6NDOs .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-WYhY6Mfad6W6NDOs .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-WYhY6Mfad6W6NDOs .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-WYhY6Mfad6W6NDOs .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-WYhY6Mfad6W6NDOs .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-WYhY6Mfad6W6NDOs .note-edge{stroke-dasharray:5}#mermaid-svg-WYhY6Mfad6W6NDOs .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-WYhY6Mfad6W6NDOs .error-icon{fill:#522}#mermaid-svg-WYhY6Mfad6W6NDOs .error-text{fill:#522;stroke:#522}#mermaid-svg-WYhY6Mfad6W6NDOs .edge-thickness-normal{stroke-width:2px}#mermaid-svg-WYhY6Mfad6W6NDOs .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-WYhY6Mfad6W6NDOs .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-WYhY6Mfad6W6NDOs .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-WYhY6Mfad6W6NDOs .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-WYhY6Mfad6W6NDOs .marker{fill:#333}#mermaid-svg-WYhY6Mfad6W6NDOs .marker.cross{stroke:#333}:root { --mermaid-font-family: "trebuchet ms", verdana, arial;}#mermaid-svg-WYhY6Mfad6W6NDOs {color: rgba(0, 0, 0, 0.75);font: ;}
减库存
完整事务
记录购买明细
数据落地
购买行为:记录秒杀成功的信息:谁购买成功;成功的时间/有效期;付款/发货信息。
秒杀难点在于用户竞争。MySql处理方法为事务+行级锁:
事务:start transaction;update 库存数量;insert 购买明细;commit。竞争出现在update减库存上。
行级锁:一个用户执行update,另外的用户等待。
秒杀功能:秒杀接口暴露;执行秒杀;相关查询。
代码开发阶段:DAO设计编码;Service设计编码;Web设计编码。
DAO层设计与开发
数据库设计
数据库初始化脚本:
-- 数据库初始化脚本-- 创建数据库
create database seckill;
-- 使用数据库
use seckill;
-- 创建秒杀库存表
create table seckill
(`seckill_id` bigint not null auto_increment comment '商品库存id',`name` varchar(120) not null comment '商品名称',`number` int not null comment '库存数量',`start_time` timestamp not null comment '秒杀开启时间',`end_time` timestamp not null comment '秒杀结束时间',`create_time` timestamp not null default current_timestamp comment '创建时间',primary key (seckill_id),key idx_start_time (start_time),key idx_end_time (end_time),key idx_create_time (create_time)
) engine = InnoDBauto_increment = 1000default charset = utf8 comment ='秒杀库存表';
-- Auto-increment 会在新记录插入表中时生成一个唯一的数字,默认开始值为1,每条新纪录递增1
-- 初始化数据
insert into seckill(name, number, start_time, end_time)
values ('1000元秒杀iphone6', '100', '2015-11-01 00:00:00', '2015-11-02 00:00:00'),('500元秒杀ipad2', '200', '2015-11-01 00:00:00', '2015-11-02 00:00:00'),('300元秒杀小米6', '300', '2015-11-01 00:00:00', '2015-11-02 00:00:00'),('200元秒杀红米note', '400', '2015-11-01 00:00:00', '2015-11-02 00:00:00');-- 秒杀成功明细表
-- 用户登录认证相关的信息
create table success_killed
(`seckill_id` bigint not null comment '秒杀商品id',`user_phone` bigint not null comment '用户手机号',`state` tinyint not null default -1 comment '状态标识:-1:无效 0:成功 1:已付款 2:已发货',`create_time` timestamp not null comment '创建时间',primary key (seckill_id, user_phone), /*联合主键*/key idx_create_time (create_time)
) engine = InnoDBdefault charset = utf8comment ='秒杀成功明细表';
-- 联合主键:防止用户对同一产品重复秒杀
-- 连接数据库控制台
-- mysql -uroot -p
DAO实体与接口编码
对照数据库建立Seckill实体类以及SuccessKilled实体类。
建立实体类的接口SeckillDao和SuccessKilledDao。
package dql.seckill.dao;import dql.seckill.entity.Seckill;
import org.apache.ibatis.annotations.Param;import java.util.Date;
import java.util.List;
import java.util.Map;public interface SeckillDao {/*** 减库存** @param seckillId* @param killTime* @return 如果影响行数>1,表示更新的记录行数*/int reduceNumber(@Param("seckillId") long seckillId, @Param("killTime") Date killTime);/*** 根据id查询秒杀对象** @param seckillId* @return*/Seckill queryById(long seckillId);/*** 根据偏移量查询秒杀商品列表* xxMapper.xml中的#{}中的参数根据@Param括号中的参数来获取相应的数据** @param offset* @param limit* @return*/List<Seckill> queryAll(@Param("offset") int offset, @Param("limit") int limit);/*** 使用存储过程执行秒杀** @param paramMap*/void killByProcedure(Map<String, Object> paramMap);
}
加入@Param(“offset”) 是因为java不保存形参的记录,所以需要mybatis提供的注解@Param标记实际的形参
package dql.seckill.dao;import dql.seckill.entity.SuccessKilled;
import org.apache.ibatis.annotations.Param;public interface SuccessKilledDao {/*** 插入购买明细,可过滤重复** @param seckillId* @param userPhone* @return 插入的行数*/int insertSuccessKilled(@Param("seckillId") long seckillId, @Param("userPhone") long userPhone);/*** 根据id查询SuccessKilled并携带秒杀产品对象实体** @param seckillId* @return*/SuccessKilled queryByIdWithSeckill(@Param("seckillId") long seckillId, @Param("userPhone") long userPhone);
}
基于myBatis实现DAO
创建mybatis-config.xml和mapper映射xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configurationPUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration><!-- 配置全局属性--><settings><!-- 使用jdbc的getGeneratedKeys 获取数据库自增主键值--><setting name="useGeneratedKeys" value="true"/><!--使用列别名替换列名,默认:true--><setting name="useColumnLabel" value="true"/><!-- 开启驼峰命名转换--><setting name="mapUnderscoreToCamelCase" value="true"/></settings>
</configuration>
映射的xml名与实体类名保持一致
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="dql.seckill.dao.SeckillDao"><!--目的:为DAO接口方法提供sql语句配置--><update id="reduceNumber"><!-- 具体sql-->updateseckillset number=number - 1where seckill_id = #{seckillId}and start_time <![CDATA[ <= ]]> #{killTime}and end_time >= #{killTime}and number> 0;</update><select id="queryById" resultType="Seckill" parameterType="long">select seckill_id, name, number, start_time, end_time, create_timefrom seckillwhere seckill_id = #{seckillId}</select><select id="queryAll" resultType="Seckill" parameterType="int">select seckill_id, name, number, start_time, end_time, create_timefrom seckillorder by create_time desclimit #{offset},#{limit}</select><!--mybatis调用存储过程--><select id="killByProcedure" statementType="CALLABLE">call execute_seckill(#{seckillId,jdbcType=BIGINT,mode=IN},#{phone,jdbcType=BIGINT,mode=IN},#{killTime,jdbcType=TIMESTAMP,mode=IN},#{result,jdbcType=INTEGER,mode=OUT})</select>
</mapper>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="dql.seckill.dao.SuccessKilledDao"><insert id="insertSuccessKilled"><!-- 主键冲突,报错-->insert ignore into success_killed(seckill_id, user_phone,state)values (#{seckillId}, #{userPhone},0)</insert><resultMap id="SuccessKilled" type="SuccessKilled"><id column="seckill_id" property="seckillId"/><result column="user_phone" property="userPhone"/><result column="create_tiem" property="createTime"/><result column="state" property="state"/><association property="seckill" javaType="Seckill"><id column="seckill_id" property="seckillId"/><result column="name" property="name"/><result column="number" property="number"/><result column="start_time" property="startTime"/><result column="end_time" property="endTime"/><result column="create_time" property="createTime"/></association></resultMap><select id="queryByIdWithSeckill" resultMap="SuccessKilled"><!-- 根据id查询SuccessKilled并携带Seckill实体--><!-- 如何告诉MyBatis把结果映射到SuccessKilled同时映射seckill属性--><!-- myBatis核心:可以自由控制Sql-->select sk.seckill_id,sk.user_phone,sk.create_time,sk.state,s.seckill_id,s.name,s.number,s.start_time,s.end_time,s.create_timefrom success_killed skinner join seckill s on sk.seckill_id = s.seckill_idwhere sk.seckill_id = #{seckillId} and sk.user_phone=#{userPhone}</select><!-- inner join(等值连接) 只返回两个表中联结字段相等的行-->
</mapper>
myBatis整合Spring编码
建立spring-dao.xml,配置整合mybatis。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttps://www.springframework.org/schema/context/spring-context.xsd"><!-- 配置整合mybatis过程--><!-- 1:配置数据库相关参数properties的属性:${url}--><context:property-placeholder location="classpath:jdbc.properties"/><!--2:数据库连接池 更换c3p0连接池为阿里Druid连接池就OK--><bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"><!-- 配置连接池属性--><property name="url" value="${jdbc.url}"/><property name="username" value="${jdbc.username}"/><property name="password" value="${jdbc.password}"/><property name="maxActive" value="${jdbc.max}"/><!-- c3p0连接池的私有属性--><!-- <property name="maxPoolSize" value="30"/>--><!-- <property name="minPoolSize" value="10"/>--><!-- <!– 关闭连接后不自动commit–>--><!-- <property name="autoCommitOnClose" value="false"/>--><!-- <!– 获取连接超时时间–>--><!-- <property name="checkoutTimeout" value="1000"/>--><!-- <!– 当获取连接失败重试次数–>--><!-- <property name="acquireRetryAttempts" value="2"/>--></bean><!-- 3:配置SqlSessionFactory对象--><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><!--注入数据库连接池--><property name="dataSource" ref="dataSource"/><!-- 配置Mybatis全局配置文件:mybatis-config.xml--><property name="configLocation" value="classpath:mybatis-config.xml"/><!-- 扫描entity包 使用别名--><property name="typeAliasesPackage" value="dql.seckill.entity"/><!-- 扫描sql配置文件:mapper需要的xml文件--><property name="mapperLocations" value="classpath:mapper/*.xml"/></bean><!-- 4.配置扫描Dao包,动态实现Dao接口,注入到spring容器中--><bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"><!-- 注入sqlSessionFactory--><property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/><!-- 给出需要扫描Dao包--><property name="basePackage" value="dql.seckill.dao"/></bean><!-- RedisDao--><bean id="redisDao" class="dql.seckill.dao.cache.RedisDao"><constructor-arg index="0" value="localhost"/><constructor-arg index="1" value="6379"/></bean>
</beans>
这里视频中使用的c3p0连接池,本地项目运行出错,换成阿里druid连接池就ok。
Service层
接口
package dql.seckill.service;import dql.seckill.dto.Exposer;
import dql.seckill.dto.SeckillExecution;
import dql.seckill.entity.Seckill;
import dql.seckill.exception.RepeatKillException;
import dql.seckill.exception.SeckillCloseException;
import dql.seckill.exception.SeckillException;import java.util.List;/*** 业务接口:站在“使用者”角度设计接口* 三个方面:方法定义粒度,参数,返回类型(return 类型/异常)*/public interface SeckillService {/*** 查询所有秒杀记录** @return*/List<Seckill> getSeckillList();/*** 查询单个秒杀记录** @param seckillId* @return*/Seckill getById(long seckillId);/*** 秒杀开启时输出秒杀接口地址* 否则输出系统时间和秒杀时间** @param seckillId*/Exposer exportSeckillUrl(long seckillId);/*** 执行秒杀操作by 存储过程** @param seckillId* @param userPhone* @param md5*/SeckillExecution executeSeckillProcedure(long seckillId, long userPhone, String md5)throws SeckillException, RepeatKillException, SeckillCloseException;SeckillExecution executeSeckill(long seckillId, long userPhone, String md5)throws SeckillException, RepeatKillException, SeckillCloseException;
}
md5用来加密。
使用Spring托管Service依赖配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xmlns:tx="http://www.alibaba.com/schema/stat"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttps://www.springframework.org/schema/context/spring-context.xsdhttp://www.alibaba.com/schema/stat http://www.alibaba.com/schema/stat.xsd"><!-- 扫描service包下所有使用注解的类型--><context:component-scan base-package="dql.seckill.service"/><!--配置事务管理器--><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><!-- 注入数据库连接池--><property name="dataSource" ref="dataSource"/></bean><!-- 配置基于注解的声明式事务默认使用注解来管理事务行为--><tx:annotation-driven/></beans>
Web层
设计Restful接口
统一资源接口要求使用标准的HTTP方法对资源进行操作,所以URI只应该来表示资源的名称,而不应该包括资源的操作。通俗来说,URI不应该使用动作来描述。
例如,下面是一些不符合统一接口要求的URI:
GET /getUser/1
POST /createUser
PUT /updateUser/1
DELETE /deleteUser/1
/模块/资源/{标识}/集合1/…
/user/{uid}/friends ->好友列表
整合配置SpringMVC框架
首先配置web.xml
整合的顺序:Mybatis->spring->springMVC
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaeehttp://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"version="3.1"metadata-complete="true"><!-- 修改servlet版本为3.1--><!-- 配置DispatcherServlet--><servlet><servlet-name>seckill-dispatcher</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><!-- 配置springMVC需要加载的配置文件spring-dao.xml,spring-service.xml,spring-web.xmlMybatis -> spring -> springMVC--><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:spring/spring-*.xml</param-value></init-param></servlet><servlet-mapping><servlet-name>seckill-dispatcher</servlet-name><!-- 默认匹配所有的请求--><url-pattern>/</url-pattern></servlet-mapping>
</web-app>
配置spring-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsdhttp://www.springframework.org/schema/contexthttps://www.springframework.org/schema/context/spring-context.xsd"><!-- 配置SpringMVC --><!-- 1:开启SpringMVC注解模式--><!-- 简化配置:(1)自动注册DefaultAnnotationHandlerMapping,AnnotationMethodHandlerAdapter(2)提供一系列:数据绑定,数字和日期的format @NumberFormat,@DataTimeFormat,xml,json默认读写支持--><mvc:annotation-driven/><!-- 2.servlet-mapping 映射路径:"/"--><!-- 静态资源默认servlet配置1:加入对静态资源的处理:js,gif,png2:允许使用"/"做整体映射--><mvc:default-servlet-handler/><!-- 3.配置jsp 显示ViewResolver--><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/><property name="prefix" value="/WEB-INF/jsp/"/><property name="suffix" value=".jsp"/></bean><!-- 4;扫描web相关的bean--><context:component-scan base-package="dql.seckill.web"/></beans>
慕课秒杀项目seckill相关推荐
- 慕课网,乐字节 Java电商秒杀项目
慕课网.乐字节Java电商秒杀项目 技术点介绍: 前端:Thymeleaf,Bootstrap,Jquerry 后端:SpringBoot,MybatisPlus,Lombok 中间件:RabbitM ...
- batocera中文整合包_分享一个整合 SSM 框架的高并发和商品秒杀项目
点击上方"Java基基",选择"设为星标" 做积极的人,而不是积极废人! 源码精品专栏 中文详细注释的开源项目 RPC 框架 Dubbo 源码解析 网络应用框架 ...
- .NET 6 Preview5+VS2022实战千万并发秒杀项目,帅爆了(附源码)
Microsoft 宣布了Visual Studio 2022 的第一个预览版,并且同时也发布了.NET 6 Preview 5.具有里程碑意义的Visual Studio 2022 Preview ...
- api商品分享源码_SSM框架高并发和商品秒杀项目高并发秒杀API源码免费分享
前言: 一个整合SSM框架的高并发和商品秒杀项目,学习目前较流行的Java框架组合实现高并发秒杀API 源码获取:关注头条号转发文章之后私信[秒杀]查看源码获取方式! 项目的来源 项目的来源于国内IT ...
- idea导入ssm项目_一个简洁的适合 Java 小白练手的“秒杀”项目
公众号关注 "GitHub今日热榜"设为 "星标",带你挖掘更多开发神器! 今天推荐一款"秒杀"项目,该项目提取自电商的秒杀场景,将秒杀业务 ...
- 小红书-内卖秒杀项目总结
文章目录 一.背景介绍 二.鸣谢 三.为什么会决定参与内卖? 四.第一次内卖 1. 前言 2. 技术方案设计 3.内卖过程中遇到的问题 4.回顾总结 四.第二次内卖 1.前言 2.技术方案设计 3.回 ...
- 秒杀项目05-页面优化技术
秒杀项目05-页面优化技术 1. 页面缓存+URL缓存+对象缓存 1.1 页面缓存 1.2 URL缓存 1.3 对象缓存(更细粒度的缓存) 2. 页面静态化,前后端分离 1. 常用技术AngularJ ...
- (更新时间)2021年6月5日 商城高并发秒杀系统(.NET Core版) 36-高并发秒杀项目k8s集群部署
秒杀项目docker部署 前提准备 k8s集群网络 serviceSubnet: "10.96.0.0/16" podSubnet: "10.100.0.0/20&quo ...
- 针对秒杀项目做的一些优化
秒杀 业务逻辑 数据库的设计 一些全局配置 JSR303参数验证(手机号) 登录 分布式Session问题? 秒杀 整体流程 优化 UserArgumentResolver 和AccessInterc ...
- 基于SpringBoot+Mybatis框架的商城秒杀项目总结
最近做了一个以SpringBoot+Mybaits为框架前后端分离的商城秒杀项目,主要使用的工具是Idea和Maven,SpringBoot是一个功能十分强大的框架集合,里面包含了很多的框架. 工程的 ...
最新文章
- MySQL数值扩大一百倍_Mysql优化----一条SQL百倍提升之旅
- Python心得基础篇【2】函数
- oracle 嵌套游标慢,oracle 嵌套游标以及java,oracle的时间处理
- Docker系列五~docker安装php-fpm
- Python摄像头录制视频保存到本地
- 【VMCloud云平台】SCSM(十)服务请求到资源落地
- 线程池如何保证所有子线程运行完再执行主线程
- check GPU mem size on condor
- PyTorch学习—12.损失函数
- LINUX上用Robot截屏得到全黑之分析
- 广域网宽带接入技术九ADSL技术
- Cplex的安装和使用实例
- c最简单的编程语言,世界上最简单的中文编程语言
- 中国大学MOOC 程序设计入门——C语言 翁凯 编程测试题汇总
- html5中required标签必填项
- arm-linux-gcc camke,Window平台基于CMake与linaro交叉编译arm程序
- Android渲染时间 太长,Android性能优化之渲染篇
- 网页文字涉及侵权怎么处理
- 【电气专业知识问答】问:什么叫组合电器?什么是GIS?
- 镭速软件如何使用文件同步功能?
热门文章
- 2017公共DNS服务器评估报告——公共DNS推荐(摘录)
- sin_cos_tan_cot_sec_cosec 三角函数计算器
- promise执行顺序总结
- radmin注册密码
- windows背景豆沙绿设置
- 常用Linux命令行技巧
- 华为双前置摄像头_华为P40系列的前置双摄像头到底隐藏了什么?我们一起来看看...
- windows service 2012阿里云服务器在搭建mysql时缺少msvcr100.dll文件解决方案
- 安装mysql提示:由于找不到 MSVCR100.dll
- Spring Boot基础学习笔记08