zoukankan      html  css  js  c++  java
  • JSONObject登录接口

    service

    /**
    * 登录
    */
    @Override
    public Map<String,Object> login(String args,HttpServletRequest request) throws Exception{
    //解析json格式,获取用户名和密码
    JSONObject jsonObj=JSON.parseObject(args);
    HashMap<String, Object> map = new HashMap<>();
    String telephone = null;
    String password = null;
    try {
    telephone = jsonObj.getString("Telephone");
    password = jsonObj.getString("Password");
    } catch (Exception e) {
    map.put("Code", "201");
    map.put("Message", "参数异常");
    }
    try {
    //查询用户名是否存在
    CloudUserExample example = new CloudUserExample();
    example.createCriteria().andTelephoneEqualTo(telephone);
    List<CloudUser> list = mapper.selectByExample(example);
    if(list!=null && list.size()>0){
    //用户存在,验证密码
    if(list.get(0).getPassword()!=null && !list.get(0).getPassword().equals(password)){
    //密码错误
    map.put("Code", "204");
    map.put("Message", "密码错误");
    }else{
    //登录成功
    map.put("Code", "200");
    map.put("Data",list.get(0));
    map.put("Message", "返回成功");
    //把用户信息保存在session中
    HttpSession session = request.getSession();
    session.setAttribute(Constant.user_session,list.get(0));
    }
    }else{
    //用户不存在
    map.put("Code", "203");
    map.put("Message", "用户不存在");
    }
    } catch (Exception e) {
    map.put("Code","202");
    map.put("Message", "返回失败");
    e.printStackTrace();
    throw new MyException("系统出错!",e);
    }
    return map;
    }

    controller

    @ResponseBody
    public Map<String,Object> Login(String args,HttpServletRequest request) throws Exception{
    return service.login(args,request);
    }

    只为记录自己所学过的东西

  • 相关阅读:
    Ubuntu 安装和使用 Supervisor(进程管理)
    Ubuntu查看端口占用及关闭
    Ubuntu 上安装 SQL Server 并创建数据库
    Kafka常用命令
    sql bug
    TiDB之PCTP(数据库专家)
    04 MySQL之函数
    05 MySQL之查询、插入、更新与删除
    03 MySQL之数据类型和运算符
    06 MySQL之索引
  • 原文地址:https://www.cnblogs.com/Mingzz/p/8017765.html
Copyright © 2011-2022 走看看