上一篇https://www.cnblogs.com/taiguyiba/p/9828984.html 整合了数据库表和Dao层代码

这一篇继续设计数据封装类:

涉及到获取秒杀地址,查询,返回秒杀结果等内容

1.数据封装:

1.1 秒杀地址封装类Exposer

创建Exposer类,用于封装秒杀地址:如果开启秒杀,则返回状态、秒杀地址md5加密值和ID,如果秒杀未开启,则返回开始时间、结束时间等。

Exposer.java

package com.seckill.dto;

public class Exposer {
//是否开启秒杀
private boolean exposed;
//md5加密
private String md5;
//id
private long seckillId;
//now time
private long now;
//start time
private long start;
//end time
private long end;
public Exposer(boolean exposed, String md5,long seckillId) {
super();
this.exposed = exposed;
this.md5 = md5;
this.seckillId = seckillId;
}
public Exposer(boolean exposed, long now, long start, long end,long seckillId) {
super();
this.exposed = exposed;
this.now = now;
this.start = start;
this.end = end;
this.seckillId = seckillId;
}
public Exposer(boolean exposed, long seckillId) {
super();
this.exposed = exposed;
this.seckillId = seckillId;
}
public boolean isExposed() {
return exposed;
}
public void setExposed(boolean exposed) {
this.exposed = exposed;
}
public String getMd5() {
return md5;
}
public void setMd5(String md5) {
this.md5 = md5;
}
public long getSeckillId() {
return seckillId;
}
public void setSeckillId(long seckillId) {
this.seckillId = seckillId;
}
public long getNow() {
return now;
}
public void setNow(long now) {
this.now = now;
}
public long getStart() {
return start;
}
public void setStart(long start) {
this.start = start;
}
public long getEnd() {
return end;
}
public void setEnd(long end) {
this.end = end;
}
@Override
public String toString() {
return "Exposer [exposed=" + exposed + ", md5=" + md5 + ", seckillId=" + seckillId + ", now=" + now + ", start="
+ start + ", end=" + end + "]";
}
}

1.2 秒杀结果封装类 SeckillExecution

SeckillExecution主要用于封装秒杀结果

package com.seckill.dto;

import com.seckill.entity.SuccessKilled;
import com.seckill.enums.SeckillStateEnum;
/**
* 数据传递
* 其中并没有添加枚举类型,转换成json有问题
* @author lll
*
*/
public class SeckillExecution { private long seckillId; private int state; private String stateInfo; private SuccessKilled successKilled; public SeckillExecution(long seckillId,SeckillStateEnum seckillStateEnum, SuccessKilled successKilled) {
super();
this.seckillId = seckillId;
this.state = seckillStateEnum.getState();
this.stateInfo = seckillStateEnum.getStateInfo();
this.successKilled = successKilled;
}
public SeckillExecution(long seckillId, SeckillStateEnum seckillStateEnum) {
super();
this.seckillId = seckillId;
this.state = seckillStateEnum.getState();
this.stateInfo = seckillStateEnum.getStateInfo();
}
public SeckillExecution(SeckillStateEnum seckillStateEnum) {
super();
this.state = seckillStateEnum.getState();
this.stateInfo = seckillStateEnum.getStateInfo();
}
public long getSeckillId() {
return seckillId;
}
public void setSeckillId(long seckillId) {
this.seckillId = seckillId;
}
public int getState() {
return state;
} public void setState(int state) {
this.state = state;
} public String getStateInfo() {
return stateInfo;
} public void setStateInfo(String stateInfo) {
this.stateInfo = stateInfo;
} public SuccessKilled getSuccessKilled() {
return successKilled;
} public void setSuccessKilled(SuccessKilled successKilled) {
this.successKilled = successKilled;
} @Override
public String toString() {
return "SeckillExecution [seckillId=" + seckillId + ", state=" + state + ", stateInfo=" + stateInfo
+ ", successKilled=" + successKilled + "]";
} }

1.3 前端请求结果封装类 SeckillResult

SeckillResult<T> 用于封装前端请求的结果:

package com.seckill.dto;
/**
* 所有ajax请求封装
* @author mayn
*
*/
public class SeckillResult<T> { private boolean success; private T data; private String error; public SeckillResult(boolean success, T data) {
super();
this.success = success;
this.data = data;
} public SeckillResult(boolean success, String error) {
super();
this.success = success;
this.error = error;
} public boolean isSuccess() {
return success;
} public void setSuccess(boolean success) {
this.success = success;
} public T getData() {
return data;
} public void setData(T data) {
this.data = data;
} public String getError() {
return error;
} public void setError(String error) {
this.error = error;
}
}

1.4 常量数据字典 SeckillStateEnum

SeckillStateEnum用于封装数据字典:

package com.seckill.enums;
/**
* 使用枚举标示常量数据字典
* @author mayn
*
*/
public enum SeckillStateEnum {
SUCCESSD(,"秒杀成功"),
END(,"秒杀结束"),
REPEAT_KILL(-,"重复秒杀"),
INNER_ERROR(-,"内部错误"),
DATA_REWRITE(-,"数据篡改")
;
private int state; private String stateInfo; private SeckillStateEnum(int state, String stateInfo) {
this.state = state;
this.stateInfo = stateInfo;
} public int getState() {
return state;
} public String getStateInfo() {
return stateInfo;
}
public static SeckillStateEnum stateOf(int index) {
for(SeckillStateEnum state : values()) {
if(state.getState() == index) {
return state;
}
}
return null;
}
}

1.5 封装异常类

 RepeatKillException 重复秒杀异常类

package com.seckill.exception;

public class RepeatKillException extends RuntimeException {

    public RepeatKillException(String message, Throwable cause) {
super(message, cause);
// TODO Auto-generated constructor stub
} public RepeatKillException(String message) {
super(message);
// TODO Auto-generated constructor stub
}
}

SeckillCloseException 秒杀关闭异常类

package com.seckill.exception;

public class SeckillCloseException extends RuntimeException {

    public SeckillCloseException(String message, Throwable cause) {
super(message, cause);
// TODO Auto-generated constructor stub
} public SeckillCloseException(String message) {
super(message);
// TODO Auto-generated constructor stub
} }

SeckillException 秒杀异常类

package com.seckill.exception;

public class SeckillException extends RuntimeException {

    public SeckillException(String message, Throwable cause) {
super(message, cause);
// TODO Auto-generated constructor stub
} public SeckillException(String message) {
super(message);
// TODO Auto-generated constructor stub
} }

Java秒杀简单设计三:数据封装类的更多相关文章

  1. Java秒杀简单设计二:数据库表和Dao层设计

    Java秒杀简单设计二:数据库表Dao层设计 上一篇中搭建springboot项目环境和设计数据库表  https://www.cnblogs.com/taiguyiba/p/9791431.html ...

  2. Java秒杀简单设计一:搭建springboot环境

    项目参考:慕课网  https://www.imooc.com/learn/587 Java秒杀 开发环境 JDK1.8.Maven.Mysql.Eclipse.SpringBoot2.0.5.myb ...

  3. Java秒杀简单设计四:service层设计

    接上一篇 https://www.cnblogs.com/taiguyiba/p/9829191.html  封装了系统传递的数据类和异常类 本文继续设计service层设计: 1.SeckillSe ...

  4. WisDom.Net 框架设计(三) 数据缓存

    WisDom.Net  --数据缓存 1.几种缓存方式       1.静态全局变量 C#静态变量使用 static 修饰符进行声明,在类被实例化时创建,通过类进行访问不带有 static 修饰符声明 ...

  5. Java秒杀实战 (三)秒杀基本功能开发

    转自:https://blog.csdn.net/qq_41305266/article/details/80991687 一.两次MD5 1. 用户端: PASS = MD5( 明文 + 固定 Sa ...

  6. java web简单的对数据库存数据

    1.建立一个表,分别有Coursename,teachername,Place,Id;这些数据跟sql语句中的相对应 2.在src包目录下创建这些类 3.在WebContent目录下创建jsp,Mai ...

  7. java后台设计简单的json数据接口,设置可跨域访问,前端ajax获取json数据

    在开发的过程中,有时候我们需要设计一个数据接口.有时候呢,数据接口和Web服务器又不在一起,所以就有跨域访问的问题. 第一步:简单的设计一个数据接口. 数据接口,听起来高大上,其实呢就是一个简单的Se ...

  8. Java消息系统简单设计与实现

    前言:由于导师在我的毕设项目里加了消息系统(本来想水水就过的..),没办法...来稍微研究研究吧..简单简单... 需求分析 我的毕设是一个博客系统,类似于简书这样的,所以消息系统也类似,在用户的消息 ...

  9. 从零一起学Spring Boot之LayIM项目长成记(三) 数据库的简单设计和JPA的简单使用。

    前言 今天是第三篇了,上一篇简单模拟了数据,实现了LayIM页面的数据加载.那么今天呢就要用数据库的数据了.闲言少叙,书归正传,让我们开始吧. 数据库 之前有好多小伙伴问我数据库是怎么设计的.我个人用 ...

随机推荐

  1. LoadRunner javavuser错误排查

    Loadrunner 9.5/11 使用java 开发vsuer script需要的环境配置 本文从两个方面来讲:windows 32位操作系统:windows 64 操作系统开始之前,先说下java ...

  2. 【机翻】Deep Plug-and-Play Super-Resolution for Arbitrary

    论文 (PDF) Deep Plug-and-Play Super-Resolution for Arbitrary Blur Kernels https://www.researchgate.net ...

  3. spring+mybatise注解实现

    spring+mybatise注解实现 spring.jpa.database=MYSQL spring.datasource.type=com.alibaba.druid.pool.DruidDat ...

  4. it码农之心灵鸡汤(一)

    到底该怎么面对工作,到底怎么面临人生.到底怎么面临青春,对于打工的人来说这些一直都是心中一直无法解惑的谜团. 对于人们怎样看待工作,以前华为创始人任正非说过:非常多人问我,来公司工作有没有双休?需不须 ...

  5. python使用代理访问服务器

    python使用代理访问服务器主要有一下3个步骤: 1.创建一个代理处理器ProxyHandler: proxy_support = urllib.request.ProxyHandler(),Pro ...

  6. 页面倒计时跳转页面效果,js倒计时效果

    页面倒计时跳转页面效果,js倒计时效果 >>>>>>>>>>>>>>>>>>>> ...

  7. System.exit(0)会跳过finally块的执行

    public class test { public static void main(String[] args) { try { System.exit(0); System.out.printl ...

  8. PHP代码审计笔记--SQL注入

    0X01 普通注入 SQL参数拼接,未做任何过滤 <?php $con = mysql_connect("localhost","root"," ...

  9. Unity Shader 获取模型空间坐标

    CGPROGRAM // Physically based Standard lighting model, and enable shadows on all light types #pragma ...

  10. [Command] wc

    wc 命令可以打印目标文件的换行.单词和字节数.其中换行数 = 总行数 - 1,单词数则按照空格分隔的英文单词数进行统计,也就是说连续的汉字(短语.句子)都视作一个单词. NAME wc - 打印每个 ...