spring boot and html

How can I send an item from spring boot code to an html script using getmapping? i have some methods here, but on the html, all the items are hardcoded because im not sure how to get these methods on html
@GetMapping(path = "/items")
public @ResponseBody List<Items> listItems()
{
return itemsRepository.findAll();
}

@GetMapping(path = "/items/{id}")
public @ResponseBody Optional<Items> findItems(@PathVariable("id") Integer id)
{
return itemsRepository.findById(id);
}


@PostMapping(path = "/items")
public @ResponseBody void addItem(@RequestBody Items item)
{
itemsRepository.save(item);
}

@DeleteMapping(path = "/items/{id}")
public @ResponseBody void deleteItem(@RequestParam("id") int id)
{
itemsRepository.deleteById(id);
}

@GetMapping(path = "/items")
public @ResponseBody List<Items> listItems()
{
return itemsRepository.findAll();
}

@GetMapping(path = "/items/{id}")
public @ResponseBody Optional<Items> findItems(@PathVariable("id") Integer id)
{
return itemsRepository.findById(id);
}


@PostMapping(path = "/items")
public @ResponseBody void addItem(@RequestBody Items item)
{
itemsRepository.save(item);
}

@DeleteMapping(path = "/items/{id}")
public @ResponseBody void deleteItem(@RequestParam("id") int id)
{
itemsRepository.deleteById(id);
}

33 Replies
JavaBot
JavaBot3y ago
Hey, @dlu! Please remember to /close this post once your question has been answered!
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
dlu
dluOP3y ago
yeah like to call these on the front end ah okay thanks
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
dlu
dluOP3y ago
but is this how u call the specific methods implemented in the code above?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
dlu
dluOP3y ago
and the links are the names of the methods? or the @mapping stuff?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
dlu
dluOP3y ago
well is this gonna display all the items on the home page? or will this bring me to a new page with all the items? ^
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
dlu
dluOP3y ago
so url is just the host name? but the thing is, how do you write that on the html file? like whats the method to get functions from java?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
dlu
dluOP3y ago
and this will process the back end functions into the front end?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
dlu
dluOP3y ago
because currently we have items hardcoded onto the website, and we have the backend class for items, we just dont know how to take the methods from that class to display the items on the home page of the html
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
dlu
dluOP3y ago
i just dont understand how to connect it with the html file
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
dlu
dluOP3y ago
essentially, on the website we have items you can "buy" but they are hardcoded onto the html file because i am unsure as to how to make them the actual items objects from our items class on spring boot
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
dlu
dluOP3y ago
not really, thats what im trying to figure out
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
dlu
dluOP3y ago
im decent with java, unexperienced with html
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
dlu
dluOP3y ago
well were not really using js is the thing were making an extremely basic site
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
dlu
dluOP3y ago
but is this supposed to be somewhere in the html file?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
dlu
dluOP3y ago
dont worry about it thanks for the help
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
dlu
dluOP3y ago
is this possible to do without javascript?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
JavaBot
JavaBot3y ago
Post Closed
This post has been closed by <@164157974053388288>.

Did you find this page helpful?