I’m developing a Spring Boot aplication with Thymeleaf, and in a Controller I have two GetMappings with differents url’s routes returning the same template.
@Controller
@RequestMapping("/detalhes")
public class DetailsAltController {
@Autowired
private NotasRepository notasRepository;
@Autowired
private RespostaRepository respostaRepository;
@GetMapping("/sefaz")
public String detalheSefaz(@RequestParam("cnpjUser") String cnpjUser, @RequestParam("cnpjEmpresa") String cnpjEmpresa, @RequestParam("idAlt") Long idNota, Model model) {
model.addAttribute("cnpjUser", cnpjUser);
model.addAttribute("tipoAlt", "Alteração Sefaz");
model.addAttribute("cnpjEmpresa", cnpjEmpresa);
NotasModel nota = notasRepository.findById(idNota).get();
NotasDto notaDto = new NotasDto(idNota, nota.getData(), nota.getSerie(), nota.getNomeEmitente(), nota.getSituacao(), nota.getValor(), cnpjEmpresa);
model.addAttribute("nota", notaDto);
model.addAttribute("mes", notaDto.data().getMonth());
return "detalhes";
}
@GetMapping("/cndt")
public String detalheCndt(@RequestParam("cnpjUser") String cnpjUser, @RequestParam("cnpjEmpresa") String cnpjEmpresa, @RequestParam("idAlt") Long idResp, Model model){
model.addAttribute("cnpjUser", cnpjUser);
model.addAttribute("tipoAlt", "Alteração Cndt");
model.addAttribute("cnpjEmpresa", cnpjEmpresa);
RespostaModel resp = respostaRepository.findById(idResp).get();
RespostaDto respostaDto = new RespostaDto(resp.getStatus(), resp.getData(), resp.getNovo(), cnpjEmpresa);
model.addAttribute("mes", resp.getData().getMonth());
model.addAttribute("resp", respostaDto);
return "detalhes";
}
}
When I acess the first route the JS runs correctly, but when I acess the second it doesn’t. Here is my html file.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Detalhes</title>
<link rel="stylesheet" href="../styles/reset.css">
<link rel="stylesheet" href="../styles/detalhes.css">
<link rel="stylesheet" href="../styles/style.css">
<script type="text/javascript" th:src="@{/js/main.js}" defer></script>
</head>
Why this is occuring, and how can I fix this?
New contributor
Mateus de Assis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.