DelegateCommand RefreshCommand 刷新 ObservableCollection 绑定的 DataGrid

如何解决DelegateCommand RefreshCommand 刷新 ObservableCollection 绑定的 DataGrid

当我向数据库添加新行时,我正在尝试更新我的 DataGrid(名称:dgLicenseholder,绑定到 ObservableCollection。我正在使用 MVVMLight)。 为什么这不起作用?

在我的 ViewModel 中,我有一个 public DelegateCommand RefreshCommand {get; private set; } 和一个方法:

private void Refresh() {

    licenseHolders.Add(new LicenseHolders());
}

licenseHolders 是一个 ObservableCollection 列表,如下所示:

public ObservableCollection<LicenseHolders> licenseHolders { get; }
    = new ObservableCollection<LicenseHolders>();

LicenseHolders 是我的 Model 中的一个类,用于保存数据:

public class LicenseHolders {
    public int ID { get; set; }
    public string Foretaksnavn { get; set; }
    // more like the above...
}

在 XAML 中,我已将命令绑定到这样的按钮;

Command="{Binding RefreshCommand}"
CommandParameter="{Binding ElementName=dgLicenseHolder}"

我更新数据库的方法放在 ViewModel 中,并由包含 DataGrid 的窗口的代码隐藏中的点击事件调用。

AddToDB()

NewLicenseHolder nlh = Application.Current.Windows.OfType<NewLicenseHolder>().FirstOrDefault();

try {

   using (SqlConnection sqlCon = new(connectionString))
   using (SqlCommand sqlCmd = new(sqlString,sqlCon)) {

        sqlCon.Open();
        
        sqlCmd.Parameters.AddWithValue("@Foretaksnavn,nlh.txtForetaksnavn.Text.ToString());
        // more of the above...
        sqlCmd.ExecuteNonQuery();
    }
}

问题 1:

我绑定 RefreshCommand 的方式有什么问题?我添加到数据库的方法工作正常,但我必须重新打开 DataGrid 的窗口才能“捕获”更改。

问题 2:

如何绑定用于更新数据库的方法而不将其放入点击事件中?

更新代码(尝试实施用户 ChrisBD 建议的解决方案)

LicenseHolder.cs - 持有者类(模型)

namespace Ridel.Hub.Model {

    public class LicenseHolder {

        public int ID { get; set; }
        public string Foretaksnavn { get; set; }
        public string Foretaksnummer { get; set; }
        public string Adresse { get; set; }
        public int Postnummer { get; set; }
        public string Poststed { get; set; }
        public string BIC { get; set; }
        public string IBAN { get; set; }
        public string Kontakt { get; set; }
        public string Epost { get; set; }
        public string Tlf { get; set; }
        public string Kontonummer { get; set; }
    }
}

RidelHubMainViewModel.cs (ViewModel)

using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using GalaSoft.MvvmLight.CommandWpf;
using Ridel.Hub.Model;

namespace Ridel.Hub.ViewModel {

    public class RidelHubMainViewModel : INotifyPropertyChanged {

        public event PropertyChangedEventHandler PropertyChanged;

        public ICommand RefreshCommand { get; private set; }

        public ObservableCollection<LicenseHolder> LicenseHolders { get; set; }

        public RidelHubMainViewModel() {

            RefreshCommand = new RelayCommand(this.ExecuteRefreshCommand);
            LicenseHolders = new ObservableCollection<LicenseHolder>();
            FillDataGridLicenseHolders();
        }

        private void ExecuteRefreshCommand() {

            NewLicenseHolder nlh = Application.Current.Windows.OfType<NewLicenseHolder>().FirstOrDefault();

            if (LicenseHolders == null) {

                LicenseHolders = new ObservableCollection<LicenseHolder>();

            } else {

                AddToDB();
                LicenseHolders.Clear();
                LicenseHolders.Add(new LicenseHolder() { Foretaksnavn = nlh.txtForetaksnavn.Text.ToString() });
                LicenseHolders.Add(new LicenseHolder() { Foretaksnummer = nlh.txtForetaksnr.Text.ToString() });
                LicenseHolders.Add(new LicenseHolder() { Adresse = nlh.txtAdresse.Text.ToString() });
                LicenseHolders.Add(new LicenseHolder() { Postnummer = Convert.ToInt32(nlh.txtPostnummer.Text.ToString()) });
                LicenseHolders.Add(new LicenseHolder() { Poststed = nlh.txtPoststed.Text.ToString() });
                LicenseHolders.Add(new LicenseHolder() { BIC = nlh.txtBIC.Text.ToString() });
                LicenseHolders.Add(new LicenseHolder() { IBAN = nlh.txtIBAN.Text.ToString() });
                LicenseHolders.Add(new LicenseHolder() { Kontakt = nlh.txtKontakt.Text.ToString() });
                LicenseHolders.Add(new LicenseHolder() { Epost = nlh.txtEpost.Text.ToString() });
                LicenseHolders.Add(new LicenseHolder() { Tlf = nlh.txtTlf.Text.ToString() });
                LicenseHolders.Add(new LicenseHolder() { Kontonummer = nlh.txtKontonr.Text.ToString() });
            }
        }

        public void FillDataGridLicenseHolders() {

            // Initially populates my DataGrid with the Sql server table
            try {

                using (SqlConnection sqlCon = new(ConnectionString.connectionString))
                using (SqlCommand sqlCmd = new("select * from tblLicenseHolder",sqlCon))
                using (SqlDataAdapter sqlDaAd = new(sqlCmd))
                using (DataSet ds = new()) {

                    sqlCon.Open();
                    sqlDaAd.Fill(ds,"tblLicenseHolder");

                    foreach (DataRow dr in ds.Tables[0].Rows) {

                        LicenseHolders.Add(new LicenseHolder {

                            ID = Convert.ToInt32(dr[0].ToString()),Foretaksnavn = dr[1].ToString(),Foretaksnummer = dr[2].ToString(),Adresse = dr[3].ToString(),Postnummer = (int)dr[4],Poststed = dr[5].ToString(),BIC = dr[6].ToString(),IBAN = dr[7].ToString(),Kontakt = dr[8].ToString(),Epost = dr[9].ToString(),Tlf = dr[10].ToString(),Kontonummer = dr[11].ToString()
                        });
                    }
                }

            } catch (Exception ex) {

                MessageBox.Show(ex.Message,"Message",MessageBoxButton.OK,MessageBoxImage.Information);
            }
        }

        private void OnPropertyChanged(string myLicenseHolder) {

            PropertyChanged?.Invoke(this,new PropertyChangedEventArgs(myLicenseHolder));       
        }

        private void OnLicenseHoldersPropertyChanged() {

            PropertyChanged?.Invoke(this,new PropertyChangedEventArgs("LicenseHolders"));
        }

        #region Slett løyvehaver
// How I delete rows from the DataGrid
        private static bool RemoveFromDB(LicenseHolder myLicenseHolder) {

            string sqlString = $"Delete from tblLicenseHolder where ID = '{myLicenseHolder.ID}'";
            
            if (MessageBox.Show("Er du sikker på at du ønsker å slette valgt løyvehaver?","Slett løyvehaver",MessageBoxButton.YesNo,MessageBoxImage.Warning) == MessageBoxResult.Yes) {
                
                try {

                    using (SqlConnection sqlCon = new(ConnectionString.connectionString))
                    using (SqlCommand sqlCmd = new(sqlString,sqlCon)) {

                        sqlCon.Open();
                        sqlCmd.ExecuteNonQuery();
                        return true;
                    }

                } catch {

                    return false;
                }

            } else {

                return false;
            }
        }

        private void RemoveLicenseHolderExecute(LicenseHolder myLicenseHolder) {
            
            bool result = RemoveFromDB(myLicenseHolder);
            if (result)
                LicenseHolders.Remove(myLicenseHolder);
        }

        private RelayCommand<LicenseHolder> _removeLicenseHoldersCommand;

        public RelayCommand<LicenseHolder> RemoveLicenseHoldersCommand => _removeLicenseHoldersCommand
            ??= new RelayCommand<LicenseHolder>(RemoveLicenseHolderExecute,RemoveLicenseHolderCanExecute);

        private bool RemoveLicenseHolderCanExecute(LicenseHolder myLicenseHolder) {

            return LicenseHolders.Contains(myLicenseHolder);
        }

        #endregion

        public void AddToDB() {

            string sqlString = "insert into tblLicenseHolder (Foretaksnavn,Foretaksnummer,Adresse,Postnummer,Poststed,BIC,IBAN,Kontakt,Epost,Tlf,Kontonummer) " +
                "values (@Foretaksnavn,@Foretaksnummer,@Adresse,@Postnummer,@Poststed,@BIC,@IBAN,@Kontakt,@Epost,@Tlf,@Kontonummer)";

            NewLicenseHolder nlh = Application.Current.Windows.OfType<NewLicenseHolder>().FirstOrDefault();

            try {

                using (SqlConnection sqlCon = new(ConnectionString.connectionString))
                using (SqlCommand sqlCmd = new(sqlString,sqlCon)) {

                    sqlCon.Open();

                    if (string.IsNullOrEmpty(nlh.txtForetaksnavn.Text) || string.IsNullOrEmpty(nlh.txtForetaksnr.Text)
                        || string.IsNullOrEmpty(nlh.txtAdresse.Text) || string.IsNullOrEmpty(nlh.txtPostnummer.Text)
                        || string.IsNullOrEmpty(nlh.txtPoststed.Text) || string.IsNullOrEmpty(nlh.txtBIC.Text)
                        || string.IsNullOrEmpty(nlh.txtIBAN.Text) || string.IsNullOrEmpty(nlh.txtKontakt.Text)
                        || string.IsNullOrEmpty(nlh.txtEpost.Text) || string.IsNullOrEmpty(nlh.txtTlf.Text)
                        || string.IsNullOrEmpty(nlh.txtKontonr.Text)) {

                        MessageBox.Show("Vennligst fyll ut alle tekstboksene.");
                        sqlCon.Close();

                    } else {                       

                        sqlCmd.Parameters.AddWithValue("@Foretaksnavn",nlh.txtForetaksnavn.Text.ToString());
                        sqlCmd.Parameters.AddWithValue("@Foretaksnummer",nlh.txtForetaksnr.Text.ToString());
                        sqlCmd.Parameters.AddWithValue("@Adresse",nlh.txtAdresse.Text.ToString());
                        sqlCmd.Parameters.AddWithValue("@Postnummer",nlh.txtPostnummer.Text);
                        sqlCmd.Parameters.AddWithValue("@Poststed",nlh.txtPoststed.Text.ToString());
                        sqlCmd.Parameters.AddWithValue("@BIC",nlh.txtBIC.Text.ToString());
                        sqlCmd.Parameters.AddWithValue("@IBAN",nlh.txtIBAN.Text.ToString());
                        sqlCmd.Parameters.AddWithValue("@Kontakt",nlh.txtKontakt.Text.ToString());
                        sqlCmd.Parameters.AddWithValue("@Epost",nlh.txtEpost.Text.ToString());
                        sqlCmd.Parameters.AddWithValue("@Tlf",nlh.txtTlf.Text.ToString());
                        sqlCmd.Parameters.AddWithValue("@Kontonummer",nlh.txtKontonr.Text.ToString());
                        sqlCmd.ExecuteNonQuery();
                                                                  
                        MessageBox.Show("Ny løyvehaver lagret. Husk å oppdatere listen.");
                    }
                }

            } catch (Exception ex) {

                MessageBox.Show(ex.Message,MessageBoxImage.Information);
            }
        }
    }
}

查看,代码隐藏 - 父窗口(LicenseHoldersWindow)

using System.Windows;
using System.Windows.Controls;
using Ridel.Hub.ViewModel;

namespace Ridel.Hub {

    public partial class LicenseHoldersWindow : Window {

        public LicenseHoldersWindow() {
            
             InitializeComponent();
             DataContext = new RidelHubMainViewModel();
        }

        private btnNew_Click(object sender,RoutedEventArgs e) {

             NewLicenseHolder newLicenseHolder = new();
             newLicenseHolder.ShowDialog();
        }
    }
}

视图,XAML - 父窗口(LicenseHoldersWindow)


<Window
    x:Class="Ridel.Hub.LicenseHoldersWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:Ridel.Hub"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:viewmodel="clr-namespace:Ridel.Hub.ViewModel"
    Title="License Holders"
    d:DataContext="{d:DesignInstance Type=viewmodel:RidelHubMainViewModel}"
    mc:Ignorable="d">

<!-- GUI stuff -->
<!-- also button to open new child-window "NewLicenseHolder" -->

<DataGrid
        x:Name="dgLicenseHolder"       
        AutoGenerateColumns="False"       
        IsReadOnly="True"
        ItemsSource="{Binding LicenseHolders,Mode=OneWay}"
        SelectionChanged="dgLicenseHolder_SelectionChanged"
        SelectionMode="Single">

查看,代码隐藏子窗口(NewLicenseHolder)

using System.ComponentModel;
using System.Windows;
using Prism.Commands;
using Ridel.Hub.ViewModel;

namespace Ridel.Hub {

    public partial class NewLicenseHolder : Window,INotifyPropertyChanged {

        public NewLicenseHolder() {
            
            InitializeComponent();
            btnLogOut.Content = UserInfo.UserName;
            DataContext = new RidelHubMainViewModel();
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void btnLagre_Click(object sender,RoutedEventArgs e) {

        // Button: Save new LicenseHolder
           ((RidelHubMainViewModel)DataContext).RefreshCommand.Execute(null);
           this.Close();
        }
    }
}

视图,XAML-子窗口(NewLicenseHolder)

<Window
    x:Class="Ridel.Hub.NewLicenseHolder"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:viewmodel="clr-namespace:Ridel.Hub.ViewModel"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    d:DataContext="{d:DesignInstance Type=viewmodel:RidelHubMainViewModel}"
    mc:Ignorable="d">

<Button
      Name="btnLagre"
      Foreground="White"
      HorizontalContentAlignment="Center"
      Click="btnLagre_Click"
      Command="{Binding RefreshCommand}"
      Style="{DynamicResource ButtonWithRoundCornersGreen}" >
</Button>

好的,所以,如果你通读了所有这些:上帝保佑。 如您所见,我在子表单中添加了新的行信息,单击保存,理想情况下,我希望我的 DataGrid 自动更新(无需单击任何额外的“刷新”或“更新”按钮。

现在发生的情况是,当我单击保存时,出现错误: System.NullReferenceException: 'Object reference not set to an instance of an object.' Local1 was null. 在我的 AddToDB() 方法中,在 if-else statement 处,我检查没有任何文本框为空。 所以我在 NewLicenseHolder class 中引用 ViewModel 的方式显然有问题:

NewLicenseHolder nlh = Application.Current.Window.OfType<NewLicenseHolder>().FirstOrDefault();

如何正确引用它,并确保在离开子窗体并返回父窗体时更新 DataGrid?

非常感谢,非常感谢任何指导纠正我的想法!

解决方法

好吧,关于数据库代码如何链接到您的代码,我在这里没有看到很多内容,但这可能会有所帮助:

public class ViewModel
{
    public ViewModel() 
    {
        RefreshCommand = new Command(async()=> await ExecuteRefreshCommand());
        LicenceHolders = new ObservableCollection<LicenceHolder>();
    }

    public ICommand RefreshCommand { get; private set; }
    public ObservableCollection<LicenceHolder> LicenceHolders { get; set; }

    private async Task ExecuteRefreshCommand()
    {
        if (LicenceHolders == null)
        {
            LicenceHolders = new ObservableCollection<LicenceHolder>();
        }
        LicenceHolders.Clear();

        //Code here for async retrieval of licence holder records from database 
        //and addition of new LicenceHolder instances to the LicenceHolders collection
    }
}

在视图 XAML 中

<Button Text="Refresh" Command="{Binding RefreshCommand}"/> 这将触发 RefreshCommand

使用 ViewModel 注入查看背后的代码

public partial class SomeView : ContentPage
{
    public SomeView(ViewModel viewModel) 
    {
        InitializeComponent();
        BindingContext = viewModel;
    }
}

否则

public partial class SomeView : ContentPage
    {
        public SomeView() 
        {
            InitializeComponent();
            BindingContext = new ViewModel();
        }
    }

理想情况下,您需要使用命令来触发 ViewModel 中的事件或处理。这可以通过在上面的视图中绑定或像这样从后面的代码中触发

private void Button_OnClick(object sender,OnClickEventArgs e)
{
   ((ViewModel)BindingContext).RefreshCommand.Execute();
}

严格来说,我们应该使用一个标志来指示正在进行的异步数据库访问 - 这可以通过在 ViewModel 中使用公共布尔值(标志)来实现,该标志用作 Command 实例中的 CanExecute 条件创建,这将阻止对同一代码的多次调用,直到它完成为止。 例如

视图模型: bool IsBusy {get;set;} 在调用异步数据访问例程之前设置为真,完成后设置为假

在构造函数中,命令实例化现在变成 RefreshCommand = new Command(async()=> await ExecuteRefreshCommand(),()=>!IsBusy);

XAML 绑定会自动选择这一点,但如果您使用代码背后的代码来触发命令,这将变为:

if (((ViewModel)BindingContext).RefreshCommand.CanExecute())
{
   ((ViewModel)BindingContext).RefreshCommand.Execute();
}

注意: 如果您在运行时用新实例替换 LicenceHolders ObservableCollection,而不是更改其内容,那么您将需要通过调用 OnPropertyChanged 处理程序手动引发/调用 PropertyChanged。 例如

protected void OnLicenHoldersPropertyChanged()
{
   PropertyChanged?.Invoke(this,new PropertyChangedEventArgs("LicenceHolders"));
}
,

看来我可能混淆了 MVVM 框架 - 无论如何,这里有一些 MVVMLite 的工作代码。

   public class LicenseHolder
{
    public string Name { get; set; }
}

public class ViewModel
{
    public ViewModel()
    {
        RefreshCommand = new GalaSoft.MvvmLight.CommandWpf.RelayCommand(this.ExecuteRefreshCommand);
        LicenseHolders = new ObservableCollection<LicenseHolder>();
    }
    public ICommand RefreshCommand { get; private set; }
    public ObservableCollection<LicenseHolder> LicenseHolders { get; set; }
    private void ExecuteRefreshCommand(object o)
    {
        if (LicenseHolders == null)
        {
            LicenseHolders = new ObservableCollection<LicenseHolder>();
        }
        LicenseHolders.Clear();
        //Code here for async retrieval of licence holder records from database 
        //and addition of new LicenceHolder instances to the LicenceHolders collection
        LicenseHolders.Add(new LicenseHolder(){Name ="Ted"});
        LicenseHolders.Add(new LicenseHolder(){Name = "Bill"});

    }
}

查看:

<Window x:Class="WpfApp1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:WpfApp1"
    mc:Ignorable="d"
    Title="MainWindow" Height="450" Width="800">
<Window.Resources>
    <local:ViewModel x:Key="ViewModelAsDataSource" />
</Window.Resources>

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition />
        <RowDefinition />
        <RowDefinition />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="40"/>
        <ColumnDefinition/>
        <ColumnDefinition Width="40"/>
    </Grid.ColumnDefinitions>
    <DataGrid Grid.Column="1" Grid.Row="1" ItemsSource="{Binding LicenseHolders }" AutoGenerateColumns="false">
        <DataGrid.Columns>
            <DataGridTextColumn Header="License Holder Name" Width="Auto" MinWidth="18" Binding="{Binding Name }" />
        </DataGrid.Columns>

    </DataGrid>

    <Button Grid.Column="1" Grid.Row="2" Content="Refresh" Command="{Binding RefreshCommand}" Width="50" Height="30"/>
     <Button Grid.Column="1" Grid.Row="3" Content="Refresh" Click="ButtonBase_OnClick" Width="50" Height="30"/>

背后的代码:

    public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        DataContext = new ViewModel();
    }
    private void ButtonBase_OnClick(object sender,RoutedEventArgs e)
    {
        ((ViewModel)DataContext).RefreshCommand.Execute(null);
    }

}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)&gt; insert overwrite table dwd_trade_cart_add_inc &gt; select data.id, &gt; data.user_id, &gt; data.course_id, &gt; date_format(
错误1 hive (edu)&gt; insert into huanhuan values(1,&#39;haoge&#39;); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive&gt; show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 &lt;configuration&gt; &lt;property&gt; &lt;name&gt;yarn.nodemanager.res