实例介绍
【实例截图】
【核心代码】
package com.gsebp.app.api.controller; import javax.annotation.Resource; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.gsebp.app.api.commons.Constants; import com.gsebp.app.api.commons.JsonMessage; import com.gsebp.app.api.commons.RunTimeMessage; import com.gsebp.app.api.service.CompanyService; import com.gsebp.app.api.service.IdentifyingCodeService; import com.gsebp.app.api.vo.CompanyRegisterVo; import com.gsebp.app.api.vo.UserLoginVo; /** * * 地区(省市区)API * * @ProjectName: [gsebp-app] * @Package: [com.gsebp.app.api.controller.UserController] * @ClassName: [UserController] * @Description: [一句话描述该类的功能] * @Author: [niurs] * @CreateDate: [2016年1月27日 下午1:53:21] * @UpdateUser: [niurs] * @UpdateDate: [2016年1月27日 下午1:53:21] * @UpdateRemark: [说明本次修改内容] * @Version: [v2.0] * */ @Controller @RequestMapping("/api-bin") public class UserController { @Value("${usernameRegular}") private String usernameRegular; @Value("${passwordRegular}") private String passwordRegular; @Value("${mobileRegular}") private String mobileRegular; @Value("${emailRegular}") private String emailRegular; @Value("${identifyingCodeRegular}") private String identifyingCodeRegular; @Value("${companyNameRegular}") private String companyNameRegular; @Resource private CompanyService companyService; @Resource private IdentifyingCodeService identifyingCodeService; @RequestMapping("/companyRegist.json") @ResponseBody public JsonMessage companyRegist(CompanyRegisterVo companyRegisterVo){ JsonMessage json=validateCompanyRegistVo(companyRegisterVo); if(json.getRet().equals(Constants.API_JSON_VALUE_RET_FAIL)){ return json; } RunTimeMessage<String> tokenRtm = companyService.companyRegist(companyRegisterVo); if(tokenRtm.getStatus()==RunTimeMessage.SUCCESS){ json.setRet(Constants.API_JSON_VALUE_RET_SUCCESS); json.setMsg("注册成功"); json.setData(tokenRtm.getDate()); identifyingCodeService.delIdentifyingCode(companyRegisterVo.getMobile()); return json; } json.setRet(Constants.API_JSON_VALUE_RET_SUCCESS); json.setMsg("注册失败"); return json; } @RequestMapping("/companyLogin.json") @ResponseBody public JsonMessage companyLogin(UserLoginVo userLoginVo){ JsonMessage json=validateUserLoginVo(userLoginVo); if(json.getRet().equals(Constants.API_JSON_VALUE_RET_FAIL)){ return json; } RunTimeMessage<String> tokenRtm = companyService.companyLogin(userLoginVo); if(tokenRtm.getStatus()==RunTimeMessage.SUCCESS){ json.setRet(Constants.API_JSON_VALUE_RET_SUCCESS); json.setMsg("登录成功"); json.setData(tokenRtm.getDate()); return json; } json.setRet(Constants.API_JSON_VALUE_RET_SUCCESS); json.setMsg("用户名或密码错误"); return json; } /** * @Name: UserController.java * @Description: @param * @Description: @return * @Author: Niurs * @CreateDate 20162016年2月14日上午11:37:20 * @Parameters: * @Return: JsonMessage */ private JsonMessage validateUserLoginVo(UserLoginVo userLoginVo) { JsonMessage jsonMessage=new JsonMessage(); if(userLoginVo.getUsername()==null || userLoginVo.getUsername().trim().equals("")){ jsonMessage.setRet(Constants.API_JSON_VALUE_RET_FAIL); jsonMessage.setMsg("用户名不能为空"); return jsonMessage; }else if(!userLoginVo.getUsername().matches(usernameRegular)){ jsonMessage.setRet(Constants.API_JSON_VALUE_RET_FAIL); jsonMessage.setMsg("用户名不合法;字母开头,长度5-15,由字母、数字及" "_" "组成"); return jsonMessage; } if(userLoginVo.getPassword()==null || userLoginVo.getPassword().trim().equals("")){ jsonMessage.setRet(Constants.API_JSON_VALUE_RET_FAIL); jsonMessage.setMsg("密码不能为空"); return jsonMessage; }else if(!userLoginVo.getPassword().matches(passwordRegular)){ jsonMessage.setRet(Constants.API_JSON_VALUE_RET_FAIL); jsonMessage.setMsg("用户名不合法;长度5-15,由字母、数字及常用特殊符号组成"); return jsonMessage; } jsonMessage.setRet(Constants.API_JSON_VALUE_RET_SUCCESS); jsonMessage.setMsg("输入信息验证成功"); return jsonMessage; } /** * * @Name: UserController.java * @Description: @param * @Description: @return * @Author: Niurs * @CreateDate 20162016年2月14日上午11:39:05 * @Parameters: * @Return: JsonMessage */ private JsonMessage validateCompanyRegistVo(CompanyRegisterVo companyRegisterVo){ JsonMessage jsonMessage=new JsonMessage(); if(companyRegisterVo.getUsername()==null || companyRegisterVo.getUsername().trim().equals("")){ jsonMessage.setRet(Constants.API_JSON_VALUE_RET_FAIL); jsonMessage.setMsg("用户名不能为空"); return jsonMessage; }else if(!companyRegisterVo.getUsername().matches(usernameRegular)){ jsonMessage.setRet(Constants.API_JSON_VALUE_RET_FAIL); jsonMessage.setMsg("用户名格式错误;字母开头,长度5-15,由字母、数字及" "_" "组成"); return jsonMessage; } if(companyRegisterVo.getPassword()==null || companyRegisterVo.getPassword().trim().equals("")){ jsonMessage.setRet(Constants.API_JSON_VALUE_RET_FAIL); jsonMessage.setMsg("密码不能为空"); return jsonMessage; }else if(!companyRegisterVo.getPassword().matches(passwordRegular)){ jsonMessage.setRet(Constants.API_JSON_VALUE_RET_FAIL); jsonMessage.setMsg("密码格式错误;长度5-15,由字母、数字及常用特殊符号组成"); return jsonMessage; } if((companyRegisterVo.getEmail()!=null && companyRegisterVo.getEmail().trim()!="") && !companyRegisterVo.getEmail().matches(emailRegular)) { jsonMessage.setRet(Constants.API_JSON_VALUE_RET_FAIL); jsonMessage.setMsg("邮箱格式错误"); return jsonMessage; } if(companyRegisterVo.getMobile()==null || companyRegisterVo.getMobile().trim().equals("")){ jsonMessage.setRet(Constants.API_JSON_VALUE_RET_FAIL); jsonMessage.setMsg("手机号不能为空"); return jsonMessage; }else if(!companyRegisterVo.getMobile().matches(mobileRegular)){ jsonMessage.setRet(Constants.API_JSON_VALUE_RET_FAIL); jsonMessage.setMsg("手机号码格式错误;长度5-15,由字母、数字及常用特殊符号组成"); return jsonMessage; } if(companyRegisterVo.getIdentifyingCode()==null || companyRegisterVo.getIdentifyingCode().trim().equals("")){ jsonMessage.setRet(Constants.API_JSON_VALUE_RET_FAIL); jsonMessage.setMsg("验证码不能为空"); return jsonMessage; }else if(!companyRegisterVo.getIdentifyingCode().matches(identifyingCodeRegular)){ jsonMessage.setRet(Constants.API_JSON_VALUE_RET_FAIL); jsonMessage.setMsg("验证码格式错误;长度6,由数字组成"); return jsonMessage; }else{ if(!identifyingCodeService.validateIdentifyingCode(companyRegisterVo.getIdentifyingCode(), companyRegisterVo.getMobile())){ jsonMessage.setRet(Constants.API_JSON_VALUE_RET_FAIL); jsonMessage.setMsg("验证码错误,请重新输入"); return jsonMessage; } } if(companyRegisterVo.getCompanyName()== null || companyRegisterVo.getCompanyName().trim().equals("")){ jsonMessage.setRet(Constants.API_JSON_VALUE_RET_FAIL); jsonMessage.setMsg("公司名称不能为空"); return jsonMessage; }else if(!companyRegisterVo.getCompanyName().matches(companyNameRegular)){ jsonMessage.setRet(Constants.API_JSON_VALUE_RET_FAIL); jsonMessage.setMsg("公司名称格式错误,长度2-20,由汉字组成"); } RunTimeMessage<String> rtm=companyService.validateCompanyName(companyRegisterVo); if(rtm.getStatus()==RunTimeMessage.SUCCESS ){ jsonMessage.setRet(Constants.API_JSON_VALUE_RET_SUCCESS); jsonMessage.setMsg("输入信息验证成功"); return jsonMessage; }else{ jsonMessage.setRet(Constants.API_JSON_VALUE_RET_FAIL); jsonMessage.setMsg(rtm.getMsg()); return jsonMessage; } } }
标签:
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论