在使用Layui的table元素时,传入的json的数据格式是有其自身定义的,需要另外添加一些字符,以正确传入。

为了传入符合前端格式的数据:

        table.render({
elem: '#test'
,url:'http://localhost:8080/pictures'
,toolbar: '#toolbarDemo' //开启头部工具栏,并为其绑定左侧模板
,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义,去除该参数即可
title: '提示'
,layEvent: 'LAYTABLE_TIPS'
,icon: 'layui-icon-tips'
}]
,title: '用户数据表'
,cols: [
[
{type: 'checkbox', fixed: 'left'}
,{field: 'id', title: 'ID', width:80, sort: true, fixed: 'left', totalRowText: '合计:'}
,{field: 'picname', title: '名字', width:200}
,{field: 'character', title: '属性', width:150}
,{field: 'home', title: '栖息地', width: 200}
,{field: 'url', title: 'url', width: 300}
,{fixed: 'right', title: '操作',width: 165, align:'center', toolbar: '#barDemo'}
]
]
,page: true
});

在entity层,使用了transient 修饰符对字段进行限定:

@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity(name="picture")
public class Picture {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@Column(name = "picname")
private String picname;
@Column(name = "type")
private transient String type;
@Column(name = "url")
private String url; @Column(name = "userid")
private transient Long userid;
@Column(name = "englishname")
private transient String englishname;
@Column(name = "character")
private String character;
@Column(name = "home")
private String home;
}

在传入中,为了满足Layui的格式要求,加上了一些头部:code、msg、count、data

    @RequestMapping("pictures")
public String getPictures(HttpSession session){
User user=(User)session.getAttribute("user");
Long userid=user.getId();
List<Picture> pictures;
if(userid==1)
pictures=picService.getAllPicture();
else
pictures=picMapper.getPicbyUserid(userid);
String picstring=gson.toJson(pictures);
log.info(" 序列化结果:" + "{ \"code\": 0, \"msg\": \"\",\"count\": 15,\"data\": "+picstring+"}");
picstring="{ \"code\": 0, \"msg\": \"\",\"count\": 10,\"data\": "+picstring+"}";
return picstring;
}

最终成功传入,显示:

【归纳】Layui table.render里的json后台传入的更多相关文章

  1. layui之table.render使用(含后台详细代码实现)

    效果图如下: 前端实现代码如图(完整代码): <!DOCTYPE html> <html> <head> <meta charset="utf-8& ...

  2. layui.table前端+后台处理+分页

    前端 注:监听工具条没有详细写,但路子一样的 @section head{ <script src="~/Content/jquery-easyui-1.5.5.4/jquery.ea ...

  3. layui 学习笔记一:layui table 查询、新增、编辑、删除

    一.table数据的呈现(对应查询) 页面代码: @{ ViewBag.Title = "TableGrid"; } @section styles{ <link href= ...

  4. layui table 分页 记住之前勾选的数据

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. layui table表格详解

    上次做table有些东西 忘记了 这次当作来个分析总结一下  跟大家共同学习 闲话不多说 直接上例子   代码: <form id="form1" runat="s ...

  6. 数据表格 layui.table

    layui官网-表单 自动渲染 方法渲染 table.render,cols中的field是后台传递的data map.put("data",stuService.selectSt ...

  7. LayUI+SSM实现一个简单的后台管理系统

    该后台管理系统是用于管理视频网站数据的,目前分5个菜单项,这篇博客主要讲述[影片管理]的具体功能和实现 后台代码结构和[影片管理]的界面如下图 该界面分为上下2部分,[搜索条件]和[影片列表],2部分 ...

  8. layui table数据表格reload where参数保留问题

    layui table数据表格reload where参数保留问题 在使用layui过程中多多少少会遇到些问题 table reload 有个坑:reload时where参数会保留上次的参数,如果用 ...

  9. Layui table 组件的使用:初始化加载数据、数据刷新表格、传参数

    背景 笔者之前一直使用 bootstrap table ,因为当前项目中主要使用 Layui 框架,于是也就随了 Layui table ,只是在使用的时候出现了一些问题,当然也是怪自己不熟悉的锅吧! ...

随机推荐

  1. Day46(列表标签,表格标签,表单标签,css的引入方式,css选择器)

    一.列表标签 列表标签分为三种. 1.无序列表<ul>,无序列表中的每一项是<li> 英文单词解释如下: ul:unordered list,“无序列表”的意思. li:lis ...

  2. HTML计算机代码元素

    计算机代码 1 2 3 4 5 6 var person = {     firstName:"Bill",     lastName:"Gates",     ...

  3. 数字类别生成onehot

    对应行的列#原始标签 my_label = np.array([3,4,2,4,6,1]) #类别数量 num_class = 6 #样本数量 num = my_label.shape[0] #生成o ...

  4. Appium解决native+webview混合型APP(公众号、小程序)切换webview后元素无法定位问题

    问题:最近在做一个安卓+H5混合开发的APP自动化测试,发现在从native切换到webview后,元素仍然无法找到,报错:no such element 思路:于是思考webview会不会像web页 ...

  5. ASP 转换HTML特殊字符

    Function HtmlDecode(ByVal s) If Has(s) Then s = regReplace(s, "<br\s*/?\s*>", vbCrLf ...

  6. [Ctsc2015]misc

    https://lydsy.com/JudgeOnline/problem.php?id=4055 题解 观察题目要我们求的东西: \[ ans[k]=\sum_{i}\sum_j \frac{a_i ...

  7. JavaScript .filter() 方法全解析

    .filter是一个内置的数组迭代方法,它接受一个"谓词(译者注: 指代一个过滤条件的函数)",该"谓词"针对每个值进行调用,并返回一个符合该条件(" ...

  8. java 图片裁剪代码

    package com.actionsoft.apps.addons.invoice.pc.test; import java.awt.image.BufferedImage;import java. ...

  9. CentOS7.4下载与安装 、使用

    CentOS7.4下载与安装 1:安装步骤这篇博客挺详细的就不多说了: https://blog.csdn.net/qq_39135287/article/details/83993574 2:安装好 ...

  10. Linux_自制系统服务启动脚本

    目录 目录 前言 Case语句 Apache 启动脚本 Postfix service 启停脚本 前言 在Linux的某些系统服务中,需要自己定制启动服务的脚本.通常会使用Cash语句来实现. Cas ...