0
私のデータベースからindex.htmlページに既にデータを取得しているビューサービスを含めることを試みています。私はSpringとThymeleafを使用しています。データベースから別のテンプレートビューにデータを取得するUsingThymeleafテンプレートビュー
これは、その後、私は私のindex.htmlを
<!--/*/ <th:block th:include="services :: #services"></th:block> /*/-->
しかし、index.htmlのにフラグメントを含める私のサービスコントローラ
@Controller
public class MyServicesController{
@Autowired
private ServicesForOurServices servicesForOurServices;
@RequestMapping(value = "myservices",method = RequestMethod.GET)
public String myServices(Model model){
model.addAttribute("services",servicesForOurServices.listAll());
return "services";
}
@RequestMapping(value = "services",method = RequestMethod.GET)
public ModelAndView listAll() {
ModelAndView modelAndView = new ModelAndView("services");
modelAndView.addObject("services",servicesForOurServices.listAll());
return modelAndView;
}
@ModelAttribute("services")
public Iterable<MyServices> services() {
System.out.println("Inside service without model");
return servicesForOurServices.listAll();
}
}
そして、私のサービステンプレートビュー
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head lang="en">
<title>Services</title>
<!--/*/ <th:block th:include="fragments/headerinc :: head"></th:block> /*/-->
</head>
<body th:fragment="services">
<!--/*/ <th:block th:include="fragments/header :: header"></th:block> /*/-->
<div th:if="${not #lists.isEmpty(services)}" class="container-fluid text-center" id="services">
<h2>SERVICES</h2>
<h4>What we offer</h4>
<div th:each="service : ${services}">
<div class="col-sm-4">
<span th:class="${service.getIcon()}"></span>
<h4 th:text="${service.getName()}"></h4>
<p th:text="${service.getDescription()}"></p>
</div>
</div>
</div>
</body>
</html>
ですサービスを含むdivではなくh2タグとh4タグのみをレンダリングします
と私はアクセスする場合services.htmlのすべてがうまくレンダリング事前