2017-02-06 71 views
0

我想包括視圖服務已經從我的數據庫檢索數據到我的index.html頁面。我正在使用春天和Thymeleaf。UseThymeleaf模板視圖與從數據庫檢索數據到另一個模板視圖

這是我的服務控制器

@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> 

然後我包括片段到我的index.html

<!--/*/ <th:block th:include="services :: #services"></th:block> /*/--> 

不過的index.html只呈現h2和h4標記而不是包含服務的div

But the index.html only render the h2 and h4 tag and not the div containing the services ,如果我訪問services.html一切使得提前

回答

0

精細 and if I access the services.html everything renders fine 感謝你有沒有檢查從瀏覽器中的元素,看看是否有提取圖片中的任何錯誤?渲染後懷疑URL不正確。

相關問題