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