Error resolving template "Meutemplate", template Might not exist or Might not be accessible by any of the configured Template Resolvers SPRING

Asked

Viewed 4,559 times

0

Performing an ajax request

function buscarDisciplina(){
        var codigoDisciplina = String($("#codigo").val());
        $.ajax({
            url: urlApplication+"/grade-curricular/buscar-disciplina/"+codigoDisciplina,
            type: 'GET',
            data: codigoDisciplina,
            dataType: 'JSON',
            success: function(response) {
                $("#disciplina").val(response);
            }
        });
}

Which calls the controller

@PreAuthorize("hasAuthority('PERM_GRADE_CURRICULAR_CADASTRAR')")
@RequestMapping(value = "/buscar-disciplina/{codigoDisciplina}")
public Disciplina bucarDisciplina(@PathVariable String codigoDisciplina) {
    return disciplinaService.findByCodigo(codigoDisciplina);
}

Service

public Disciplina findByCodigo(String codigo){
    return disciplinaRepository.findByCodigo(codigo);
}

Repository

public Disciplina findByCodigo(String codigo); //uso JpaRepository<Disciplina, Long>

Entity

@Size(max = 10)
@NotEmpty
@Column(name = "codigo")
private String codigo;

However when sending the request inserir a descrição da imagem aqui

It gives the error of the above image ... I have no idea what it could be ....

  • urlApplication that you asked at the url, that’s correct?

  • Yes, it goes on top of the @Requestmapping controller(value = "/seek-discipline/{codeDiscipline}") correctly, but gives this error

  • 1

    @Proctontesla tries to put the note @ResponseBody in his method bucarDisciplina, this way he sends a json as an answer, he won’t look for a template that doesn’t exist

1 answer

1


The error occurs because you did not put the annotation @ResponseBody in his method bucarDisciplina, If you do not place this annotation Thymeleaf will try to find a template with the return of the method.

How do you want only one returned json, just place this annotation indicating that the return of the method is the content to be displayed by the browser

Another way to do this is to configure the annotation @RequestMapping as follows:

@RequestMapping(value = "/buscar-disciplina/{codigoDisciplina}", produces = MediaType.APPLICATION_JSON_VALUE)

Browser other questions tagged

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