Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

462
Visualizações
Need to access/send var data from JavaScript to Java Spring Boot Controller ThymeLeaf

I'm still learning JS, Thymeleaf, and Spring Boot and can't seem to figure out how I can use data variables in my JavaScript file and send them to a database through Spring MVC controller. Here is what I have so far:

html:

<body>

<!--PRINT OUT TEST_VAR HERE FOR USERS TO SEE DATA-->

<script src="../static/js/TEST.js" type="text/javascript" th:src="@{/js/TEST.js}"></script>

</body>

JavaScript:

var TEST_VAR = 37;

Java/Spring MVC Controller:

@RequestMapping(value = "TEST_VAR", method = RequestMethod.GET)
    public String messages(Model model) {
        model.addAttribute("test_db", "test_var");
        return "TESTindex";
// Not sure what to write in the controller.
    }

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

in a SpringBoot Controller, the "value" in the requestmap annotation is where the end point is binded to

so the example below binds to "abc.com/api/v1/17" and 17 is the variable that will be readed from path (because if you use GET method, you need to read data from path) Get methods doesn't have request body (investigate GET and POST method diffrences, if you need )

@RequestMapping(value = "/api/v1/{id}", method = GET)
public String getFoosBySimplePathWithPathVariable(
  @PathVariable("id") String id) {
    return "you send id = " + id;
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda