Java Community | Help. Code. Learn.JC|HCL
Java Community | Help. Code. Learn.โ€ข4y agoโ€ข
10 replies
dlu

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);
    }
Was this page helpful?