layui+SpringBoot上传图片到数据库并展示在页面(从数据库读取数据展示)

插入数据成功之后我们就要将数据展示出来
在这里插入图片描述

页面样式设计

<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 我要打卡 </button>
            </div>
        </script>
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
    </div>
</div>
<script>
    layui.use(['form', 'table','miniPage','element'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            miniPage = layui.miniPage;
        window.reload=function(){
            table.reload('currentTableId');
        }
        table.render({
            elem: '#currentTableId',
            url: 'health/queryAllHealth',//查询所有请假信息
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {type: "checkbox", width: 50},
                // {field: 'id', width: 80, title: 'ID', sort: true},
                {templet:'<div>{{ d.user.username}}</div>', width: 90, title: '学生'},
                {templet:'<div>{{ d.user.tel}}</div>', width: 110, title: '联系方式'},
                {templet:"<div>{{ layui.util.toDateString(d.pushTime,'yyyy-MM-dd HH:mm:ss')}}</div>", width: 160, title: '打卡时间'},
                {field: 'iso', width: 90, title: '是否隔离'},
                {field: 'cough', width: 120, title: '是否咳嗽'},
                {field: 'fever',width: 120, title: '是否发烧'},
                {field: 'trip', width: 200, algin:'center', title: '行程码',templet : '#img_trip'},
                {field: 'health', width: 200, algin:'center', title: '健康码',templet: '#img_health'},
                {field: 'location', width: 100, title: '打卡位置'},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });

        /**
         * toolbar事件监听
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {   // 监听添加操作
                var content = miniPage.getHrefContent('page/health/add.html');
                var openWH = miniPage.getOpenWidthHeight();
                var index = layer.open({
                    title: '我要打卡',
                    type: 1,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['60%', '60%'],
                    content: content,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            }
        });
</script>
<script type="text/html" id="img_trip">
    <img src="{{d.trip}}" width="200" height="250" alt="">
</script>
<script type="text/html" id="img_health">
    <img src="{{d.health}}" width="200" height="250" alt="">
</script>

向后端请求查询数据库数据并展示

table.render({
            elem: '#currentTableId',
            url: 'health/queryAllHealth',//查询所有请假信息
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {type: "checkbox", width: 50},
                // {field: 'id', width: 80, title: 'ID', sort: true},
                {templet:'<div>{{ d.user.username}}</div>', width: 90, title: '学生'},
                {templet:'<div>{{ d.user.tel}}</div>', width: 110, title: '联系方式'},
                {templet:"<div>{{ layui.util.toDateString(d.pushTime,'yyyy-MM-dd HH:mm:ss')}}</div>", width: 160, title: '打卡时间'},
                {field: 'iso', width: 90, title: '是否隔离'},
                {field: 'cough', width: 120, title: '是否咳嗽'},
                {field: 'fever',width: 120, title: '是否发烧'},
                {field: 'trip', width: 200, algin:'center', title: '行程码',templet : '#img_trip'},
                {field: 'health', width: 200, algin:'center', title: '健康码',templet: '#img_health'},
                {field: 'location', width: 100, title: '打卡位置'},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });

注意:因为要展示图片所以必须在图片的那一列加上templet : ‘#id’

 {field: 'trip', width: 200, algin:'center', title: '行程码',templet : '#img_trip'},

显示图片对应的js

<script type="text/html" id="img_trip">
    <img src="{{d.trip}}" width="200" height="250" alt="">
</script>

突然想起

在前面写的一篇关于前端的时候,提交的表单中的每个字段的name值都要对应entity中的属性,千万不能错,不然插入数据的时候插入不进去。
在这里插入图片描述

查询所有打卡信息的后端接口

@RequestMapping("/queryAllHealth")
    public JsonObject queryAllHealth(@RequestParam(defaultValue = "1") Integer page,
                                     @RequestParam(defaultValue = "15")Integer limit,
                                     Health health, HttpSession session){
        JsonObject jsonObject=new JsonObject();
        User user= (User) session.getAttribute("user");
        //System.out.println(user.getId()+user.getUsername());
        if(user.getRoleName().equals("学生")){
            health.setUserId(user.getId());
            //System.out.println(health.getUserId());
        }
        PageInfo<Health> pageInfo = healthService.queryPageHealth(page, limit, health);
        jsonObject.setMsg("ok");
        jsonObject.setCode(0);
        jsonObject.setCount(pageInfo.getTotal());
        jsonObject.setData(pageInfo.getList());
        return  jsonObject;
    }
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值