2017-11-29 10:46
@yjjdick1990 是的,接口提出的数据就是json格式的就好了,接口访问状态码,消息等一目了然。
2017-11-23 21:54
给个例子你参考:package com.platform.admin.agent.user;
import com.platform.base.BaseController;
import com.platform.base.BaseValidator;
import com.jfinal.core.Controller;
/**
* 用户信息验证
* Created by sloft.com on 2016/12/12.
*/
public class AgentUserValidator extends BaseValidator {
@Override
protected void validate(Controller c) {
BaseController cc = (BaseController) c;
if ("GET".equals(cc.getRequest().getMethod())) {
return;
}
setShortCircuit(true);
switch (getActionKey()) {
case "/mbz/login":
validateRequired("username", "userNameMsg", "帐户不能为空");
// validateMobile("username", "userNameMsg", "手机格式不正确");
validateRequired("password", "passwordMsg", "密码不能为空");
// validateCaptcha("captcha", "captchaMsg", "验证码不正确");
break;
case "/admin/password":
validateRequired("password1", "password1Msg", "请输入原始密码");
validateRequired("password2", "password2Msg", "请输入新密码");
break;
case "/admin/user/pass":
validateRequired("pass1", "pass1_msg", "请输入原密码");
validateRequired("pass2", "pass2_msg", "请输入新密码");
break;
case "/admin/user/add":
validateRequired("role", "roleMsg", "请选择所属角色");
if (cc.getPara("role").equals("0")) {
addError("roleMsg", "请选择所属角色");
}
String username = cc.getPara("username");
if (AgentUserService.me.isAccountExists(username)) {
addError("usernameMsg", "该手用户已被注册,请重新输入");
}
if ("admin".equals(username) || "superadmin".equals(username) || "root".equals(username)) {
addError("usernameMsg", "该用户名为系统内置用户,请重新输入");
}
validateRequired("phone", "phoneMsg", "手机号码不能为空");
validateMobile("phone", "phoneMsg", "请输入正确的手机号码");
validateRequired("password", "passwordMsg", "密码不能为空");
validatePassword("password", "passwordMsg", "密码格式不正确,请输入由字母或者下划线组成的格式");
validateString("password", 1, 32, "passwordMsg", "密码不能超过32个字");
validateRequired("nickname", "nicknameMsg", "姓名/昵称不能为空");
validateString("nickname", 1, 32, "nicknameMsg", "昵称不能超过19个字");
break;
case "/admin/user/update":
validateRequired("role", "roleMsg", "请选择所属角色");
if (cc.getPara("role").equals("0")) {
addError("roleMsg", "请选择所属角色");
}
// validateRequired("phone", "phoneMsg", "手机号码不能为空");
// validateMobile("phone", "phoneMsg", "请输入正确的手机号");
validateRequired("password", "passwordMsg", "密码不能为空");
validatePassword("password", "passwordMsg", "密码格式不正确,请输入由字母或者下划线组成的格式");
validateString("password", 1, 32, "passwordMsg", "密码不能超过32个字");
validateRequired("nickname", "nicknameMsg", "姓名/昵称不能为空");
validateString("nickname", 1, 32, "nicknameMsg", "昵称不能超过19个字");
break;
}
}
@Override
protected void handleError(Controller c) {
c.renderJson();
}
}