java判断对象工具类,java对象结果工具类

import java.io.Serializable;

/**

* @ClassName: SuccessOrFailure

* @Description: json对象结果类

* @author: private

* @date: 2018年2月1日 下午3:46:18

*/

public class SuccessOrFailure implements Serializable {

private static final long serialVersionUID = 2782974536561798941L;

private boolean success;

private Object message;

public SuccessOrFailure() {}

private SuccessOrFailure(boolean success, Object message) {

this.success = success;

this.message = message;

}

public static SuccessOrFailure SUCCESS = new SuccessOrFailure(true, null);

public static SuccessOrFailure SUCCESS(Object message) {

return new SuccessOrFailure(true, message);

}

public static SuccessOrFailure FAILURE(Object message) {

return new SuccessOrFailure(false, message);

}

public boolean isSuccess() {

return success;

}

public void setSuccess(boolean success) {

this.success = success;

}

public Object getMessage() {

return message;

}

public void setMessage(Object message) {

this.message = message;

}

@Override

public String toString() {

return "SuccessOrFailure [success=" + success + ", message=" + message + "]";

}

}

用法示例

import java.io.FileOutputStream;

import java.io.OutputStream;

import java.text.SimpleDateFormat;

import java.util.ArrayList;

import java.util.Date;

import java.util.List;

import javax.annotation.Resource;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;

import org.springframework.web.bind.annotation.ResponseBody;

import com.fh.controller.base.BaseController;

import com.fh.service.system.carappuser.CarAppUserManager;

import com.fh.util.AppUtil;

import com.fh.util.PageData;

import sun.misc.BASE64Decoder;

@Controller

@RequestMapping("/app")

public class AppController extends BaseController {

private static final Logger logger = Logger.getLogger(AppController.class);

@Resource

private CarAppUserManager carAppUserService;

@RequestMapping("/login")

@ResponseBody

public SuccessOrFailure login(String data,HttpServletRequest request) throws Exception {

AppUtil appUtil = new AppUtil(data, request);

try {

// 效验秘钥

/*appUtil.verifySign();*/

// 获取手机号

String phone = appUtil.getParam("phone") == null ? "" : appUtil.getParam("phone").toString();

// 获取账号

String account = appUtil.getParam("account") == null ? "" : appUtil.getParam("account").toString();

// 获取密码密码

String password = appUtil.getParam("password") == null ? "" : appUtil.getParam("password").toString();

// 创建参数map

PageData pd = this.getPageData();

// 判断登录方式

if (!Tools.isEmpty(phone)) { // 手机号登录

pd.put("USER_PHONE", phone);

pd.put("loginType", LoginType.LOGIN_TYPE_PHONE);

} else if (Tools.isEmpty(account)) { // 账号登录

pd.put("USER_ACCOUNT", account);

pd.put("loginType", LoginType.LOGIN_TYPE_ACCOUNT);

}

// 获取用户信息

PageData appUser = carAppUserService.findUserByLoginType(pd);

// 获取用户密码

String appUserPassword = appUser.getString("PASSWORD");

// 密码是否匹配

if (appUserPassword.equals(MD5.md5(password + Const.SALT))) {

return SuccessOrFailure.SUCCESS(appUser);

} else {

return SuccessOrFailure.FAILURE("密码错误");

}

} catch (SignErrorException e) {

return SuccessOrFailure.FAILURE(e.getMessage());

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值