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:

@Controller

    @RequestMapping
    public class VendingMachineController {
    
        @GetMapping("/vending-machine")
        public String juice() {
            return "vending-machine";
        }
    
        @PostMapping("/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="http://www.thymeleaf.org" lang="en">
<head>
    <meta charset="UTF-8">
    <title>VendingMachine</title>
</head>
<body>


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

</body>
</html>