首页 > 其他分享 >腾讯公益赛冲刺个人博客1(2024.4.23)

腾讯公益赛冲刺个人博客1(2024.4.23)

时间:2024-05-06 13:11:07浏览次数:13  
标签:ps 2024.4 String 23 冲刺 public password id name

今天确定了组内第一阶段的任务是基本完成sos和帮扶两个核心功能以及登录注册等常规功能

完成登录和注册的基本页面以及数据库的设计

package com.example.helppeople.entity;

public class Student {

    private String id;
    private String name;
    private String phone;

    private String password;

    public Student() {
    }

    public Student(String id, String name, String phone, String password) {
        this.id = id;
        this.name = name;
        this.phone = phone;
        this.password = password;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}
package com.example.helppeople.dao;

import android.util.Log;

import com.example.helppeople.entity.Student;
import com.example.helppeople.utils.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashMap;

public class StudentDao {
    private static final String TAG = "mydb-StudentDao";
    private static String currentLoggedInUserId;

    public int login(String id, String password) {
        HashMap<String, Object> map = new HashMap<>();
        Connection connection = JDBCUtils.getConn();
        int msg = 0;

        try {
            String sql = "select * from student where name = ?";
            if (connection != null) {
                PreparedStatement ps = connection.prepareStatement(sql);
                if (ps != null) {
                    Log.e(TAG, "账号:" + id);
                    ps.setString(1, id);
                    ResultSet rs = ps.executeQuery();
                    int count = rs.getMetaData().getColumnCount();
                    while (rs.next()) {
                        for (int i = 1; i <= count; i++) {
                            String field = rs.getMetaData().getColumnName(i);
                            map.put(field, rs.getString(field));
                        }
                    }
                    connection.close();
                    ps.close();

                    if (map.size() != 0) {
                        StringBuilder s = new StringBuilder();
                        for (String key : map.keySet()) {
                            if (key.equals("password")) {
                                if (password.equals(map.get(key))) {
                                    msg = 1;
                                    currentLoggedInUserId = id;
                                } else
                                    msg = 2;
                                break;
                            }
                        }
                    } else {
                        Log.e(TAG, "查询结果为空");
                        msg = 3;
                    }
                } else {
                    msg = 0;
                }
            } else {
                msg = 0;
            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.d(TAG, "异常login:" + e.getMessage());
            msg = 0;
        }

        return msg;
    }

    public boolean register(Student student) {
        HashMap<String, Object> map = new HashMap<>();
        Connection connection = JDBCUtils.getConn();

        try {
            String sql = "insert into student(id, name, phone,password) values (?,?,?,?)";
            if (connection != null) {
                PreparedStatement ps = connection.prepareStatement(sql);
                if (ps != null) {
                    ps.setString(1, student.getId());
                    ps.setString(2, student.getName());
                    ps.setString(3, student.getPhone());
                    ps.setString(4, student.getPassword());

                    int rs = ps.executeUpdate();
                    if (rs > 0)
                        return true;
                    else
                        return false;
                } else {
                    return false;
                }
            } else {
                return false;
            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.e(TAG, "异常register:" + e.getMessage());
            return false;
        }
    }

    public Student findStudent(String studentId) {
        Connection connection = JDBCUtils.getConn();
        Student student = null;
        try {
            String sql = "select * from student where id = ?";
            if (connection != null) {
                PreparedStatement ps = connection.prepareStatement(sql);
                if (ps != null) {
                    ps.setString(1, studentId);
                    ResultSet rs = ps.executeQuery();

                    while (rs.next()) {
                        String id = rs.getString(1);
                        String name = rs.getString(2);
                        String phone = rs.getString(3);
                        String password = rs.getString(4);
                        student = new Student(id, name, phone, password);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.d(TAG, "异常findUser:" + e.getMessage());
            return null;
        }
        return student;
    }
}

 

标签:ps,2024.4,String,23,冲刺,public,password,id,name
From: https://www.cnblogs.com/Sunyiran/p/18174825

相关文章

  • 23 Alertmanager抑制、静默、路由、告警分组
    一、抑制机制Alertmanager的抑制机制可以避免当某种问题告警产生之后用户接收到大量由此问题导致的一系列的其它告警通知。例如当集群不可用时,用户可能只希望接收到一条告警,告诉他这时候集群出现了问题,而不是大量的如集群中的应用异常、中间件服务异常的告警通知。在Alertman......
  • “any”类型的参数不可分配给“never”类型的参数。ts(2345)
    问题引入在进行项目开发时,用到了el-tree标签,就是组织树状数据渲染页面,类似菜单,然后父级菜单下会有多个子菜单。本次总共就两层。这里遇到的问题是,后端返回的数据就是一个list,属于叶子节点,父级节点是固定的,需要前端写死,但就在写死了父级节点,并将叶子节点加入到父级节点下后,之前选......
  • 腾讯公益赛冲刺团队博客2(2024.4.24)
    未完成sos、帮扶、社交、在线医生四个功能进行中百度地图权限申请和登录注册后的主界面已完成登录注册基本内容 ......
  • 腾讯公益赛冲刺团队博客4(2024.4.26)
    未完成sos功能后端,在线医生、社交功能进行中帮扶功能的后端已完成sos、帮扶前端、登录注册、主页  ......
  • 腾讯公益赛冲刺团队博客6(2024.4.30)
    未完成sos后端、在线医生、聊天室进行中百度地图今天通过申请,开始进行sos后端已完成sos前端、帮扶全部、登录注册和主页  ......
  • 腾讯公益赛团队冲刺博客5(2024.4.29)
    未完成sos后端、在线医生、聊天室进行中细化帮扶功能的后端和数据库,调整前端页面已完成sos第一个页面、帮扶前端,登陆注册、主页 ......
  • 腾讯公益赛团队冲刺博客8(2024.5.2)
    未完成sos弹窗功能,在线医生、聊天室进行中sos弹窗功能已完成sos查看地图功能与弹窗功能、帮扶、登录注册、主页  ......
  • 腾讯公益赛团队冲刺博客7(2024.5.1)
    未完成sos地图定位功能和弹窗功能,在线医生、聊天室进行中sos的定位功能已完成sos的查看地图功能、帮扶、登录注册、主页  ......
  • 腾讯公益赛团队冲刺博客9(2024.5.3)
    未完成在线医生、聊天室、多人弹窗进行中在线数据库的连接,保证不同的网络都可以连接到一个数据库已完成sos、帮扶的基本功能,登录注册和主页  ......
  • CISCN2023-华北-normal_snake
    就得审java。又更新了,因为我前面jar包导不进去,所以把它解压了导入的,然后环境正常了就想起来把这个打了。路由分析老规矩,先看看路由:/read路由下传参data,pyload不能包含!!,然后用了yaml来load传入的参数。稍作了解,这其实就是 SnakeYaml反序列化漏洞,禁用了yaml的常用头 !!......