How to exit the controller before reaching the end with Vraptor 3?

Asked

Viewed 94 times

3

Do you have a command in vraptor 3 that will allow you to log out of the controller before you get to the end of it? 'Cause I have a controller that if a particular one happens process in the middle of it it will return an error json, and need it not give more continuity in the code.

Follow Example below:

 @Path("/metogo)
 public void Metodo(Teste teste) {

  if( aconteceAlgo  ){
     result.use(json()).indented().from(objErro).serialize();
     // Sair do controller e não continuar todo processo abaixo.
  }
  // continua o processo no Controller  
 }

NOTE: I will not redirect to any other page, just return JSON

1 answer

1

If a method returns void, you can terminate its execution using the word Return;

@Path("/metogo)
public void Metodo(Teste teste) {
    //...
    if (aconteceAlgo) {
        result.use(json()).indented().from(objErro).serialize();
        return; // <------------------
    }
    // continua o processo no Controller ...
}

Browser other questions tagged

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