Thymeleaf教程 (二) 虚拟购物商店

示例所示的源代码和本指南中未来的章节都可以在此找到Good Thymes Virtual Grocery GitHub repository.

一个购物网站

为了更好地解释Thymeleaf参与处理模板的概念,本教程将使用一个演示的应用程序,您可以从上面地址下载项目。  

这个应用程序是一个虚构的虚拟商店网站,并将为我们提供足够的场景举例说明不同Thymeleaf特性。

我们需要为我们的应用程序设计一套非常简单的实体模型: Products(商品) 通过创建orders(订单)卖给Customers(客户)。我们也管理这些产品的Comments(评论)。应用程序模型如下:

我们的小应用程序也将有一个非常简单的服务层,服务对象包含方法如下:

public class ProductService {
  ...
  public List<Product> findAll() {
    return ProductRepository.getInstance().findAll();
  }
  public Product findById(Integer id) {
    return ProductRepository.getInstance().findById(id);
  }
}

最后,在web层有一个过滤器,将根据请求URL委托执行Thymeleaf-enabled命令:

private boolean process(HttpServletRequest request, HttpServletResponse response)
throws ServletException {
  try {
    /*
    * Query controller/URL mapping and obtain the controller
    * that will process the request. If no controller is available,
    * return false and let other filters/servlets process the request.
    */
    IGTVGController controller = GTVGApplication.resolveControllerForRequest(request);
    if (controller == null) {
      return false;
    }
    /*
    * Obt
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值