java – When the button is clicked it returns a message or displays it. Spring Boot

I’m fairly new spring boot and really trying to learn as much as possible. Currently, I’m creating simple vending machine web application. I was able to display the button but don’t know how to write out a code when the button is clicked it returns a message or popup window that says “You purchased a drink” or whatever message is suitable in this senario. Additionally, I’m incorporating Thymeleaf for this small project. I’m open for ANY suggestions and I’m pretty sure I’m writing my code wrong. Thanks!

So far in my Controller I have this:


    public class VendingMachineController {
        public String juice() {
            return "vending-machine";
        public String purchasedMessage(Model model){
            model.addAttribute("You've purchased an");
            return "/vending-machine";

And this is my html file:

<!DOCTYPE html>
<html xmlns:th="" lang="en">
    <meta charset="UTF-8">

    <h2 class="title-name">Vending Machine</h2>
    <button type="submit" class="btn-buy-juice" name="purchase-btn" value="orange juice">Purchase orange juice</button>