如何用themeleaf显示图片

一.数据库中:

存的是图片的绝对路径
在这里插入图片描述

二.后端查询出该对象

@Controller
public class EmpController {
    @Autowired
    private EmpService empService;

    @RequestMapping("/getOne")
    public String emp(Integer did,Model model){
        List<Emp> emps = empService.selectEmpByDid(did);

        model.addAttribute("emps",emps);
        return "emp";
    }
}

三.前端用thymeleaf展示

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Title</title>
</head>
<body>
<table border="1" style="border-collapse: collapse">

    <tr>
        <th>ID</th>
        <th>员工名称</th>
        <th>头像</th>
    </tr>
    <tr th:each="emp:${emps}">
        <td th:text="${emp.id}"></td>
        <td th:text="${emp.name}"></td>
        <!--展示图片-->
        <td><img th:src="@{${emp.photo}}" th:width="50px" th:height="50px"/></td>

    </tr>
</table>

</body>
</html>

四.效果图

在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值