我正在做一项作业,并使用 thymeleaf 和 spring 创建网页。我已经完成了大部分工作,但我似乎无法加载图像。
我的HTML:
<!DOCTYPE html>
<html xmlns:th="https//www.thymeleaf.org">
<head>
<title>A Course</title>
<link rel="stylesheet" type="text/css"
href="/css/ReviewPageStyleSheet.css" />
</head>
<body>
<h1 id="heading">A Single Course</h1>
<img th:src="@{${'/images/' + review.image}}">
<div id="list" th:each="review: ${reviews}">
<p th:text="${review.title}"></p>
<p th:text="${review.category}"></p>
<a href="http://localhost:8080/show-all-reviews">Back to home</a>
</div>
</body>
</html>Run Code Online (Sandbox Code Playgroud)
我的控制器:
package org.wecancodeit.reviewsite;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class ReviewSiteController {
@Resource
ReviewSiteRepository reviewsRepo;
@RequestMapping("/show-all-reviews")
public String findAllReviews(Model model) {
model.addAttribute("reviews", reviewsRepo.findAll());
return "reviews";
}
@RequestMapping("review")
public String findOneReview(@RequestParam(value = …Run Code Online (Sandbox Code Playgroud)