我有一个动态外部网址,该网址是我在控制器端的模型中设置的,并试图使用thymleaf标签访问html
代码如下:
控制器:
@RequestMapping(value = "/{id:.+}", method = RequestMethod.GET)
public String searchUser(@PathVariable("id") String data, Model model) {
/*
* if (!data.startsWith("@")) { data = "@" + data; }
*/
List<User> list = userService.searchUserUsingText(data);
if (list.isEmpty()) {
System.out.println("error");
return "404";
} else {
User user = list.get(0);
if (null != user.getName())
model.addAttribute("name", user.getName());
if (null != user.getProfession())
model.addAttribute("profession", user.getProfession());
if (null != user.getPhotoUrl()) {
System.out.println("inside image" + user.getPhotoUrl());
model.addAttribute("image" + user.getPhotoUrl());
}
return "profile";
}
}
胸叶/ Html侧:
<div class="container">
<div class="owner">
<div class="avatar">
<img th:src="@{${image}}" alt="Circle Image"
class="img-circle img-no-padding img-responsive">
</div>
<div class="name">
<h4 class="title" th:text="${name}">
<br />
</h4>
<h6 class="description" th:text="${profession}"></h6>
</div>
</div>
名称和职业得到了完美的解决,但是在img Tag,我得到的是空值。
请大家帮忙...
答案 0 :(得分:1)
你有
model.addAttribute("image" + user.getPhotoUrl());
我想你打算拥有
model.addAttribute("image", user.getPhotoUrl());