如何根据用户类型获取各自的阶段?
How to get the respective stage according to the user type?
所以现在的问题是我无法提示每种类型的用户进入正确的阶段,我有一种方法可以检查他们的用户名和 return 他们的角色类型,然后它将验证用户并通过后将其提示到各自的阶段。
我已尝试进行一些调试,但 getUserRole 方法似乎有问题,因为我无法在登录控制器中进入该方法。
**登录控制器*
@FXML
public void Login(ActionEvent event) {
try {
if (this.loginModel.isLogin(this.username.getText(), this.password.getText())) {
Stage stage = (Stage) this.login.getScene().getWindow();
stage.close();
if (this.loginModel.getUserRole(this.username.getText()) == 5) {
adminLogin();
} else if (this.loginModel.getUserRole(this.username.getText()) == 4) {
technicianLogin();
} else if (this.loginModel.getUserRole(this.username.getText()) == 3) {
custServiceLogin();
} else if (this.loginModel.getUserRole(this.username.getText()) == 3) {
financeLogin();
} else if (this.loginModel.getUserRole(this.username.getText()) == 3) {
managementLogin();
} else {
this.loginStatus.setText("The username or password entered is incorrect. Please check and try again.");
}
}
} catch (Exception localException) {
this.loginStatus.setText("The username or password entered is incorrect. Please check and try again.");
}
}
获取用户角色方法
public int getUserRole(String user) throws Exception
{
PreparedStatement pr = null;
ResultSet rs = null;
String sql = "SELECT * FROM Login WHERE username = ? AND role = ?";
try
{
pr = this.connection.prepareStatement(sql);
pr.setString(1, user);
if(rs.next())//cant initialized this if statement
{
int role = rs.getInt("role");
return role;
}
else{
return 0;
}
}
catch(SQLException ex)
{
return 0;
}
finally
{
pr.close();
rs.close();
}
}
我找到了一个解决方案,好像我忘记执行查询了,将其添加到 try 块后,它似乎可以工作。
rs.executeQuery();
所以现在的问题是我无法提示每种类型的用户进入正确的阶段,我有一种方法可以检查他们的用户名和 return 他们的角色类型,然后它将验证用户并通过后将其提示到各自的阶段。
我已尝试进行一些调试,但 getUserRole 方法似乎有问题,因为我无法在登录控制器中进入该方法。
**登录控制器*
@FXML
public void Login(ActionEvent event) {
try {
if (this.loginModel.isLogin(this.username.getText(), this.password.getText())) {
Stage stage = (Stage) this.login.getScene().getWindow();
stage.close();
if (this.loginModel.getUserRole(this.username.getText()) == 5) {
adminLogin();
} else if (this.loginModel.getUserRole(this.username.getText()) == 4) {
technicianLogin();
} else if (this.loginModel.getUserRole(this.username.getText()) == 3) {
custServiceLogin();
} else if (this.loginModel.getUserRole(this.username.getText()) == 3) {
financeLogin();
} else if (this.loginModel.getUserRole(this.username.getText()) == 3) {
managementLogin();
} else {
this.loginStatus.setText("The username or password entered is incorrect. Please check and try again.");
}
}
} catch (Exception localException) {
this.loginStatus.setText("The username or password entered is incorrect. Please check and try again.");
}
}
获取用户角色方法
public int getUserRole(String user) throws Exception
{
PreparedStatement pr = null;
ResultSet rs = null;
String sql = "SELECT * FROM Login WHERE username = ? AND role = ?";
try
{
pr = this.connection.prepareStatement(sql);
pr.setString(1, user);
if(rs.next())//cant initialized this if statement
{
int role = rs.getInt("role");
return role;
}
else{
return 0;
}
}
catch(SQLException ex)
{
return 0;
}
finally
{
pr.close();
rs.close();
}
}
我找到了一个解决方案,好像我忘记执行查询了,将其添加到 try 块后,它似乎可以工作。
rs.executeQuery();