Implementation of the Java Mysql MVC model

Asked

Viewed 123 times

-3

In my model I am accessing Clientedo by the controller of my model Customer as seen in the example below. I would like to know if this practice is correct for the mvc model, since both classes (client and client controllers) are in English.

Example: verify Cpf

Class of controller

public boolean verificarCpfExistente(String cpf){
    if(ClienteDAO.getInstance().verificarCpf(cpf)==true)
        return true;
    return false;
}

Classe Clientedao

  public boolean verificarCpf(String cpf){
    String sql= "select * from cliente where cpf like ?";
      try {
         Connection conectar= conexao.getInstance().abrir();      
         PreparedStatement comando= conectar.prepareCall(sql);
         comando.setString(1,cpf);
         ResultSet resultset=comando.executeQuery(); 
         resultset.next();

         if(resultset.getString("cpf").equals(cpf))
             return true;          
      } catch (Exception e) {
        return false;      
        }
    return false;  
   }

Full project if necessary: github.com/vvieira22/programsell

1 answer

1


If your project is small I would move on to a structure similar to this:

/src/main/java/myName/appName/controller   
/src/main/java/myName/appName/model
/src/main/java/myName/appName/model/request
/src/main/java/myName/appName/model/response
/src/main/java/myName/appName/service
/src/main/java/myName/appName/dao
/src/main/java/myName/appName/vo(vo, dto, pojo)
/src/main/java/myName/appName/entity

The controller layer should never directly access the DAO layer, who makes this intermediate is the service layer.

Therefore to delete a record the controller should make a call on a service that will later call a service on the DAO layer that will effectively delete the record.

Another interesting point is that the controller should never access an Entity, Entity should be converted to a Response model, before it is sent to the controller.

And the DAO layer should not receive a model request, it should be converted to an Entity (if necessary) before the DAO layer.

  • I get it, in the event that my class is an American, is it a problem if I access it from the controller? , dao makes every connection in the customer’s bank so a English, if a customer’s Cpf exists, register a new customer etc...

  • I changed the question, see if it improves my doubt.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.