编程语言
首页 > 编程语言> > Java Cookie实现用户登录登出功能

Java Cookie实现用户登录登出功能

作者:互联网

需求: 使用Cookie实现用户登录登出功能

   @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    @Override
    public Users insertUser(UserBO userBO) {
        // 获取全局id
        String nextShort = sid.nextShort();
        Users users = new Users();
        users.setId(nextShort);
        users.setUsername(userBO.getUsername());
        users.setRealname(userBO.getUsername());
        users.setNickname(userBO.getUsername());
        try {
            users.setPassword(MD5Utils.getMD5Str(userBO.getPassword()));
        } catch (Exception e) {
            e.printStackTrace();
        }
        users.setFace("http://baidu.com");
        users.setBirthday(DateUtil.getCurrentDateTime());
        users.setCreatedTime(DateUtil.getCurrentDateTime());
        users.setUpdatedTime(DateUtil.getCurrentDateTime());
        // 插入数据
        usersMapper.insertSelective(users);
        return users;
    }

    @Override
    public Users queryUserForLogin(String username, String password) {
        // 构建条件
        Example example = new Example(Users.class);
        Example.Criteria criteria = example.createCriteria();
        // 查询条件
        criteria.andEqualTo("username", username);
        criteria.andEqualTo("password", password);
        return usersMapper.selectOneByExample(example);
    }

 

标签:DateUtil,Java,Users,登出,Cookie,userBO,getUsername,getCurrentDateTime,users
来源: https://www.cnblogs.com/ititit111222333/p/14615904.html