码迷,mamicode.com
首页 > 其他好文 > 详细

返回对象result封装

时间:2014-08-22 12:48:26      阅读:311      评论:0      收藏:0      [点我收藏+]

标签:des   java   io   数据   ar   2014   art   cti   

import tf56.sofa.serializer.JsonGenerateUtil;

/**
 * 返回对象Result封装
 * @athor changmeng.liu
 * @date 2014-7-25
 * @version 1.0
 * @update 
 */
public class Result {
	final String SUCCESS="success";
	final String ERROR="error";
	private String count="";
	/** 响应数据 */
    private Object data;
    /** 响应分页 */
	/** 响应状态 */
    private Boolean status = true;
    /** 响应消息 */
    private String message;

    public Result() {}

    public Result(Object data) {
    	this.data = data;
    }

   

    public Result(String message, Boolean status) {
    	this.set(message, status);
    }

    public Result(String message, Boolean status,String count, Object data) {
    	this.set(message, status);
    	this.data = data;
    	this.count=count;
    }

   

    public void set(String message, Boolean status) {
    	this.status = status;
    	this.message = message;
    	this.count="";
    	this.data="";
    }

    public void set(String message, Boolean status,String count, Object data) {
    	this.status = status;
    	this.message = message;
    	this.data = data;
    	this.count=count;
    }

    public Boolean getStatus() {
		return status;
	}

	public void setStatus(Boolean status) {
		this.status = status;
		this.message=this.status?"成功":"失败";
		this.count="";
    	this.data="";
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	public String getCommonJson(){
		return JsonGenerateUtil.getCommonJson(status==true?SUCCESS:ERROR, message, count==null?"":count, data==null?"":data);
	}

}
<pre name="code" class="java">public class InvitationCodeServiceImpl implements InvitationCodeService {
	@Autowired
	private InvitationCodeDao invitationCodeDao;
	@Autowired
	private PartyService partyService;
        protected Result result=new Result();
        protected final Log logger = LogFactory.getLog(getClass());


/**
	 * @athor changmeng.liu
	 * @date 2014-7-15
	 * @version 1.0
	 * @function 
	 * @param 
	 * @update 
	 */
	@Override
	public Result getInvitationCodeByTypeAndId(Map map) {
		
		String type=(String) map.get("type");
		String fromid=(String) map.get("fromid");
		if(StringUtils.isEmpty(type)){
			this.result.set("类型不能为空", false);
			logger.debug(this.result.getMessage());
			return this.result;
			
		}
		if(StringUtils.isEmpty(fromid)){
			this.result.set("来源ID不能为空", false);
			logger.debug(this.result.getMessage());
			return this.result;
			
		}
		if(!"小二".equals(type)&&!"会员".equals(type)){
			this.result.set("类型不正确", false);
			logger.debug(this.result.getMessage());
			return this.result;
		}
		Map<String,Object> paramMap=new HashMap<String,Object>();
		paramMap.put("type", type);
		paramMap.put("fromid", fromid);
		InvitationCode invitationCode=invitationCodeDao.selectByTypeAndId(paramMap);
		if(invitationCode==null){
			this.result.set("没有找到该用户的邀请码", true,"","");
			logger.debug(this.result.getMessage());
			return this.result;
		}
		this.result.set("成功", true, "1", invitationCode);
		return this.result;
	}
}




返回对象result封装,布布扣,bubuko.com

返回对象result封装

标签:des   java   io   数据   ar   2014   art   cti   

原文地址:http://blog.csdn.net/iasmn68628/article/details/38755267

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!