SSM项目之商铺系统(七) Dto之ShopExecution的实现

本文介绍SSM项目中数据传输对象(DTO)的使用,特别是ShopExecution类的实现。DTO用于封装批量数据,当服务器端需要向客户端传递包含操作结果和Shop对象信息时,ShopExecution类能同时携带这些信息,满足业务需求。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Data Transfer Object,数据传送对象 。

DTO是一个普通的Java类,它封装了要传送的批量的数据。当客户端需要读取服务器端的数据的时候,服务器端将数据封装在DTO中,这样客户端就可以在一个网络调用中获得它需要的所有数据。

Shop实体类包含了Shop的基本属性,但是在前端操作时,我们希望可以返回操作的结果等信息,这个时候Shop实体类就不能满足需求了,我们将操作结果和Shop等信息统一放到DTO中处理,即可满足当前的需求。


新建了下面的类
在这里插入图片描述

枚举类

package com.artisan.o2o.enums;

/**
 * 
 * 
 * @ClassName: ShopStateEnum
 * 
 * @Description: 使用枚举表述常量数据字典 
 */
public enum ShopStateEnum {

	CHECK(0, "审核中"), OFFLINE(-1, "非法店铺"), SUCCESS(1, "操作成功"), PASS(2, "审核通过"), INNER_ERROR(-1001, "操作失败"), NULL_SHOPID(-1002, "ShopId为空"), NULL_SHOP_INFO(-1003, "传入了空的信息");
	
	private int state;
	private String stateInfo;

	/**
	 * 
	 * 
	 * @Title:ShopStateEnum
	 * 
	 * @Description:私有构造函数,禁止外部初始化改变定义的常量
	 * 
	 * @param state
	 * @param stateInfo
	 */
	private ShopStateEnum(int state, String stateInfo) {
		this.state = state;
		this.stateInfo = stateInfo;
	}

	/**
	 * 
	 * 
	 * @Title: getState
	 * 
	 * @Description: 仅设置get方法,禁用set
	 * 
	 * @return
	 * 
	 * @return: int
	 */
	public int getState() {
		return state;
	}

	public String getStateInfo() {
		return stateInfo;
	}

	/**
	 * 
	 * 
	 * @Title: stateOf
	 * 
	 * @Description: 定义换成pulic static 暴漏给外部,通过state获取ShopStateEnum
	 * 
	 *               values()获取全部的enum常量
	 * 
	 * @param state
	 * 
	 * @return: ShopStateEnum
	 */
	public static ShopStateEnum stateOf(int state) {
		for (ShopStateEnum stateEnum : values()) {
			if(stateEnum.getState() == state){
				return stateEnum;
			}
		}
		return null;
	}

}



DTO类ShopExecution

package com.artisan.o2o.dto;

import java.util.List;

import com.artisan.o2o.entity.Shop;
import com.artisan.o2o.enums.ShopStateEnum;

/**
 * 
 * 
 * @ClassName: ShopExecution
 * 
 * @Description: DTO中还要包含操作商铺的返回结果,单个的实体类无法满足,所以封装到dto中,便于操作
 * 
 * @author: Mr.Yang
 * 
 * @date: 2018年5月19日 下午2:50:29
 */
public class ShopExecution {
	
	/**
	 * 操作结果状态
	 */
	private int  state ;

	/**
	 * 操作结果状态说明
	 */
	private String stateInfo;

	/**
	 * 店铺数量
	 */
	private int count;

	/**
	 * 店铺 (增删改店铺的时候用)
	 */
	private Shop shop;

	/**
	 * 店铺集合 (查询店铺列表的时候用)
	 */
	private List<Shop> shopList;

	
	/**
	 * 
	 * 
	 * @Title:ShopExecution
	 * 
	 * @Description: 构造函数,店铺操作失败的时候使用的构造函数
	 * 
	 * @param shopStateEnum
	 */
	public ShopExecution(ShopStateEnum shopStateEnum) {
		this.state = shopStateEnum.getState();
		this.stateInfo = shopStateEnum.getStateInfo();
	}

	/**
	 * 
	 * 
	 * @Title:ShopExecution
	 * 
	 * @Description:构造函数,店铺操作成功的时候使用的构造函数
	 * 
	 * @param stateEnum
	 * @param shop
	 */
	public ShopExecution(ShopStateEnum stateEnum, Shop shop) {
		this.state = stateEnum.getState();
		this.stateInfo = stateEnum.getStateInfo();
		this.shop = shop;
	}

	/**
	 * 
	 * 
	 * @Title:ShopExecution
	 * 
	 * @Description:构造函数,店铺操作成功的时候使用的构造函数
	 * 
	 * @param stateEnum
	 * @param shopList
	 */
	public ShopExecution(ShopStateEnum stateEnum, List<Shop> shopList) {
		this.state = stateEnum.getState();
		this.stateInfo = stateEnum.getStateInfo();
		this.shopList = shopList;
	}


	/**
	 * 
	 * setter/getter
	 * 
	 */

	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 int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public Shop getShop() {
		return shop;
	}

	public void setShop(Shop shop) {
		this.shop = shop;
	}

	public List<Shop> getShopList() {
		return shopList;
	}

	public void setShopList(List<Shop> shopList) {
		this.shopList = shopList;
	}

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值