处理异常返回值,代码调优
This commit is contained in:
parent
38b4554c98
commit
b33ec7e404
@ -19,6 +19,7 @@ public class UsersDaoImpl implements UsersDao {
|
||||
private PreparedStatement preparedStatement = null;
|
||||
private ResultSet resultSet = null;
|
||||
DataBaseUtil dataBaseUtil = new DataBaseUtil();
|
||||
|
||||
//新建用户
|
||||
@Override
|
||||
public int insert(@NotNull Users users) {
|
||||
@ -46,7 +47,7 @@ public class UsersDaoImpl implements UsersDao {
|
||||
@Override
|
||||
public int delete(@NotNull Users user) {
|
||||
String delete_sql = "delete from Users where id=?";
|
||||
CommonDao<Users> dao = new CommonDao<>();
|
||||
CommonDao dao = new CommonDao();
|
||||
return dao.delete(connection, preparedStatement, resultSet,
|
||||
delete_sql, user.getId());
|
||||
}
|
||||
@ -121,8 +122,13 @@ public class UsersDaoImpl implements UsersDao {
|
||||
dataBaseUtil.close(connection, preparedStatement, resultSet);
|
||||
}
|
||||
|
||||
if (user == null) {
|
||||
throw new RuntimeException("用户不存在");
|
||||
} else {
|
||||
return user;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetAttribute(@NotNull Users user, @NotNull ResultSet rs) throws SQLException {
|
||||
user.setId(rs.getLong("id"));
|
||||
user.setName(rs.getString("name"));
|
||||
|
Loading…
Reference in New Issue
Block a user