zoukankan      html  css  js  c++  java
  • SSM+Redis+Layui实现注册功能

    首先创建注册的html网页

    建表框架的官方获取:https://www.layui.com/doc/element/form.html

    其次找到相应的js文件(根据自己表里的name属性值进行监听提交)

    layui.use头可以在https://www.layui.com/doc/element/form.html找到

    监听提交可以在https://www.layui.com/demo/找到

    其次到Controller写注册的方法:

    这里用到了Redis,在运行前需要开启Redis(非关系型数据库)

    @PostMapping("/reg")
        public String reg(consumer sa){
            JsonData jsonData;
            Jedis jedis=new Jedis("localhost",6379);
            String s = jedis.get(sa.getPhone());
            System.out.println("验证码为:"+s);
            if (!s.equals(sa.getCodes())){
                 jsonData=JsonData.buildError("验证码error");
                return JSON.toJSONString(jsonData);
            }
             jsonData=service.insertShop(sa);
            return JSON.toJSONString(jsonData);
        }

    第三,到Service接口

    JsonData insertShop(consumer sa)

     第四:到ServiceImpl实体类敲注册的方法

    @Override
        public JsonData insertShop(consumer sa) {
            String phone = sa.getUsername();
            sa.setUsername(phone);
            consumer s = mapper.login(sa);
            if (s == null) {
                sa.setPassword("123456"); //注册成功时生成默认密码
                int i = mapper.insertShop(sa);
                if (i > 0) {
                    return JsonData.buildSuccess("success");
                }
                if (sa.getUsername().equals(sa.getUsername())) {
                    return JsonData.buildError("该账号已存在,请使用密码登录");
                }
    
            }
            return JsonData.buildError("注册失败");
        }

    第五:到Mapper接口实现方法

    int insertShop(consumer sa);

    第六:并在相对应的Mapper.xml中配置SQL语句

    在注册的时候实际上是执行添加的操作,说到这应该知道怎么写SQL语句了吧 

    一个框架的都是一样的流程,静下心来屡屡是不是思路更清晰,今天刚学习的,有些不足请您指出!

    ---------------------------------------------------------------------------------------------------------------------------------------感谢到访!期待您的下次光临!

  • 相关阅读:
    Python 函数内变量的作用域
    python return 及lambda函数
    python 函数的定义及传参
    Python 集合
    python 内置函数
    Python 字典
    Python 元组
    LoaRunner性能测试系统学习教程:Windows计数器(2)
    LoaRunner性能测试系统学习教程:操作系统监控(1)
    LoaRunner性能测试系统学习教程:结果分析实践之Summary View(8)
  • 原文地址:https://www.cnblogs.com/varchar-pig/p/14244206.html
Copyright © 2011-2022 走看看