我在添加普通用户时为用户分配了不同的权限,在权限选择时不知道如何判断,例如共用增、删、改、查4种权限而普通用户只享有其中的两种权限。如何进行判断并保存到数据库中,谢谢!!!

解决方案 »

  1.   

    没明白,4个checkbox,你选哪个就保存对应的值就是了. 
    如果用户没有设置checkebox权限,就灰化.
      

  2.   

    用JCheckBox的isSelected判断时候被选中了
    for example
    int authCount = 0;
    String addAuth = "0", delAuth = "0", updateAuto = "0", selAuto = "0";
    if (addCheckBox.isSelected()) {
        authCount++;
        addAuth = "1",
    }
    if (delCheckBox.isSelected()) {
        authCount++;
        delAuth = "1",
    }if (updateCheckBox.isSelected()) {
        authCount++;
        updateAuth = "1",
    }if (selCheckBox.isSelected()) {
        authCount++;
        selAuth = "1",
    }if (authCount > 2) {
        JOptionPane.showMessageDialog(null, "普通用户不能超过2种权限,请重选", "错误", OK_OPTION, null);
        return;
    }String sql = "insert into usertable values (xxx, yyy...";
    sql += "'" + addAuth + "', ";
    sql += "'" + delAuth + "', ";
    sql += "'" + updateAuth + "', ";
    sql += "'" + selAuth + "', ";
    sql += "zzz, ttt...)";
    stmt.executeUpdate(sql);
    ...