我用这个开发做了这个查询但是我在接收 API 时遇到问题我尝试验证用户登录但总是 API RESPONSE LOGIN SUCCESS
我用 Java Spring Boot 和 Mysql 做了这个
这是我的代码:
@Override
public List<UserDto> getUsers() {
List<UserDto> list = new ArrayList<UserDto>();
try {
Connection con = getConnection();
PreparedStatement ps = con.prepareStatement("Select * from tableregister");
ResultSet rs = ps.executeQuery();
while (rs.next()) {
UserDto data = new UserDto();
data.setName(rs.getString("name"));
data.setLastname(rs.getString("lastname"));
data.setEmail(rs.getString("email"));
data.setUsername(rs.getString("username"));
data.setNumber(rs.getString("number"));
data.setPassword(rs.getString("password"));
list.add(data);
}
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
我先做了这个
@Override
public ApiResponseDto getlogin(UserDto usersLogin) {
try{
Connection con = getConnection();
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from tableregister where username='"+usersLogin.getUsername()+"' and password='"+usersLogin.getPassword()+"'");
if (usersLogin.getUsername() != null && usersLogin.getPassword() != null) {
return new ApiResponseDto("Success", "Login: ");
} else {
ApiResponseDto apiResponseDto = new ApiResponseDto("Error", "Error Login");
apiResponseDto.setErrorCode(2);
return apiResponseDto;
}
} catch (Exception e) {
e.printStackTrace();
return new ApiResponseDto("Error", "Error: " + e.toString());
}
}
守着一只汪
慕田峪7331174
相关分类