Spring boot 如何修复为每个项目显示相同图像的问题
问题:如何修复为每个项目显示相同图像的问题 thymleaf.htmlSpring boot 如何修复为每个项目显示相同图像的问题,spring-boot,thymeleaf,Spring Boot,Thymeleaf,问题:如何修复为每个项目显示相同图像的问题 thymleaf.html <div th:each="goals : ${goals}"> <div th:text="${goals.getId()}"></div> <img th:src="@{'image/'+ ${goals.getId()}}" width="100px;" height="100px;"/> <div th:text="${goals.title}">&l
<div th:each="goals : ${goals}">
<div th:text="${goals.getId()}"></div>
<img th:src="@{'image/'+ ${goals.getId()}}" width="100px;"
height="100px;"/>
<div th:text="${goals.title}"></div>
查看页面的控制器
@GetMapping(value = "/goals")
public String read(Model model) {
model.addAttribute("login", new LogIn()); //it for bottom menu
model.addAttribute("currentlyPage","goals"); // it for top menu
model.addAttribute("addNewGoal", new addNewGoal()); //another page
//get all goals
List<Goals> goals = new ArrayList<>();
goalsRepository.findAll().forEach(goals::add);
model.addAttribute("goals",goals);
return "goals";
我希望看到不同的图像,但到处都是相同的图像。我找到了解决方案
@GetMapping(value = "/image/{id:.+}")
public @ResponseBody ResponseEntity<byte[]> showProductImage(@PathVariable String id, HttpServletResponse response) throws IOException {
Goals goals = goalsRepository.findById(UUID.fromString(id));
ByteBuffer buffer =goals.getImage();
byte[] bytes = buffer.array();
return ResponseEntity.ok().contentType(MediaType.IMAGE_JPEG).body(bytes);
}
@GetMapping(value=“/image/{id:.+}”)
public@ResponseBody ResponseEntity showProductImage(@PathVariable String id,HttpServletResponse)引发IOException异常{
Goals=goalsRepository.findById(UUID.fromString(id));
ByteBuffer buffer=goals.getImage();
byte[]bytes=buffer.array();
返回ResponseEntity.ok().contentType(MediaType.IMAGE_JPEG).body(字节);
}
@GetMapping(value = "/image/{id:.+}")
public @ResponseBody ResponseEntity<byte[]> showProductImage(@PathVariable String id, HttpServletResponse response) throws IOException {
Goals goals = goalsRepository.findById(UUID.fromString(id));
ByteBuffer buffer =goals.getImage();
byte[] bytes = buffer.array();
return ResponseEntity.ok().contentType(MediaType.IMAGE_JPEG).body(bytes);
}
@GetMapping(value=“/image/{id:.+}”)
public@ResponseBody ResponseEntity showProductImage(@PathVariable String id,HttpServletResponse)引发IOException异常{
Goals=goalsRepository.findById(UUID.fromString(id));
ByteBuffer buffer=goals.getImage();
byte[]bytes=buffer.array();
返回ResponseEntity.ok().contentType(MediaType.IMAGE_JPEG).body(字节);
}
@GetMapping(value = "/image/{id:.+}")
public @ResponseBody ResponseEntity<byte[]> showProductImage(@PathVariable String id, HttpServletResponse response) throws IOException {
Goals goals = goalsRepository.findById(UUID.fromString(id));
ByteBuffer buffer =goals.getImage();
byte[] bytes = buffer.array();
return ResponseEntity.ok().contentType(MediaType.IMAGE_JPEG).body(bytes);
}