码迷,mamicode.com
首页 > Web开发 > 详细

第一次JSON返回的登陆模式

时间:2016-10-31 16:39:27      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:object   mode   string   get   .post   str   生成   ade   i++   

/**
* 跳转到登录页
*
* @param model
* @return
*/
@RequestMapping(value = {"/login2"},method = { RequestMethod.POST, RequestMethod.GET })
@ResponseBody
public JSONObject login1(Model model, HttpServletRequest request,
HttpServletResponse response,
@RequestParam(value = "account", required = false) String account,
@RequestParam(value = "password", required = false) String password){
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Content-Type", "application/json;charset=utf-8");
StringBuilder str=new StringBuilder();//定义变长字符串
Random random=new Random();
//随机生成数字,并添加到字符串
for(int i=0;i<8;i++){
str.append(random.nextInt(10));
}
//将字符串转换为数字并输出
int num=Integer.parseInt(str.toString());
String account1 = "yy";
String password1 ="1";
JSONObject json = new JSONObject();
json.put("msg", "登陆成功");
json.put("success", true);

JSONObject obj=new JSONObject();
obj.put("userID", 1);
obj.put("userName", "名字");
obj.put("account", account);
obj.put("userType", "1/2");
obj.put("token", num);
json.put("obj", obj);

JSONObject json1 = new JSONObject();
json1.put("msg", "登陆失败/账号不存在");
json1.put("success", false);

if(account.equals(account1) && password.equals(password1)){
System.out.println(json);
return json;
}else{
return json1;
}
}

第一次JSON返回的登陆模式

标签:object   mode   string   get   .post   str   生成   ade   i++   

原文地址:http://www.cnblogs.com/ckz0105/p/6016188.html

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