Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

465
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!