1
I’m beginner in java and I’m having doubts in comparing objects by means of loop. I am developing software for a video rental company with Pattern MVC (Model-view-controller) design and I want to know how to compare the person object through his code with zero. When I loop this, it displays the following message: Bad operand types for Binary Operator '>' .
 private boolean salvarPessoa(){
            OPDatas bl = new OPDatas();
            pessoa.setNome(this.txtNome.getText());
            pessoa.setBairro(this.txtBairro.getText());
            pessoa.setEndereco(this.txtEndereco.getText());
            pessoa.setCidade(this.txtCidade.getText());
            pessoa.setUf(this.txtUF.getText());
            pessoa.setCPF(this.txtCPF.getText());
            pessoa.setTelefone(this.txtTelefone.getText());
            pessoa.setdNascimento(bl.converterDataStringParaDate(this.txtdNascimento.getText()));// 
         // Esse é o loop e o objeto pessoa!
            if (pessoaController.salvar(pessoa> 0) {
                JOptionPane.showMessageDialog(this, "Registro gravado com sucesso!");
                this.desabilitarCampos();
                this.carregarClientes();
                return true;
            } else {
                JOptionPane.showMessageDialog(this, "Erro ao gravar os dados!", "ERRO", JOptionPane.ERROR_MESSAGE);
                return false;
            }
         }
Personal controller:
public boolean salvar( String nome, String endereco, String bairro, String sexo, String telefone, String celular, String CPF, Date dNascimento, String cidade, String uf ) {
        boolean retorno;
        Pessoa pessoa = new Pessoa();
        pessoa.setNome(nome);
        pessoa.setEndereco(endereco);
        pessoa.setBairro(bairro);
        pessoa.setSexo(sexo);
        pessoa.setTelefone(telefone);
        pessoa.setCelular(celular);
        pessoa.setCPF(CPF);
        pessoa.setdNascimento(dNascimento);
        pessoa.setCidade(cidade);
        pessoa.setUf(uf);
        retorno = pessoaDAO.salvar(pessoa);
        return retorno;
    }
Why are you comparing whether the person object is greater than zero?
– Laerte
To save my person and if the code of the person object is greater than zero he saves!
– Igor Contini
By your code the save method always returns a boolean, with the return of it you know if the person saved or not, see my answer if it helps you.
– Laerte
In person Control in the save method the boolean return variable is not shown as initialized!
– Igor Contini
It makes no sense to check the Id being that in the method it is not even used (because of the parameters)
– Laerte