spring Thymeleaf从Html获取数据

oknrviil  于 2022-11-28  发布在  Spring
关注(0)|答案(1)|浏览(141)

我需要得到数据从html到控制器与按下按钮也Html数据作为列表。

<thead>
        <tr>
            <th>Company Name</th>
            <th>Book Name</th>
            <th>Author</th>
            <th>Price</th>
            <th>Order</th>
        </tr>
        </thead>
        <tbody>
        <tr th:each="Books: ${Books }">
            <td th:text="${Books.CompanyName}" />
            <td th:text="${Books.BookName}" />
            <td th:text="${Books.AuthorName}" />
            <td th:text="${Books.Price}" />
            <td th:button class="Order-Button" type="button" >Order</button> </td>

这也是我的控制器

@Autowired
    private BookRep bookRep;

    @RequestMapping(value = "/BookOrder")
    ModelAndView submitBookOrder(){
        ModelAndView mav = new ModelAndView("BookOrder");
        mav.addObject("Books", bookRep.findAll());
        return mav;

    }

我希望当用户按下接受订单按钮时,它将在控制器中获得行数据

l7mqbcuq

l7mqbcuq1#

我为你写了演示代码。我想它对你会有用。你可以通过看代码来了解你想要什么

@GetMapping("/Books/{id}")
public String books(@PathVariable("id") Long id, Model model){

    model.addAttribute("Books", bookService.getById(id));

    return "book-list";
}

<-td>图书<-a th:href="@{/Books/{id}(id = ${book.id})}"><-button type="submit" class="btn btn-info col-2" style="min-width: fit-content">列表〈-/button〉

相关问题