处理异常返回值,代码调优
This commit is contained in:
		@@ -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,9 +47,9 @@ 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<>();
 | 
			
		||||
        return  dao.delete(connection, preparedStatement, resultSet,
 | 
			
		||||
                        delete_sql, user.getId());
 | 
			
		||||
        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);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return user;
 | 
			
		||||
        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"));
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user