【归纳】Layui table.render里的json后台传入
在使用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后台传入的更多相关文章
- layui之table.render使用(含后台详细代码实现)
效果图如下: 前端实现代码如图(完整代码): <!DOCTYPE html> <html> <head> <meta charset="utf-8& ...
- layui.table前端+后台处理+分页
前端 注:监听工具条没有详细写,但路子一样的 @section head{ <script src="~/Content/jquery-easyui-1.5.5.4/jquery.ea ...
- layui 学习笔记一:layui table 查询、新增、编辑、删除
一.table数据的呈现(对应查询) 页面代码: @{ ViewBag.Title = "TableGrid"; } @section styles{ <link href= ...
- layui table 分页 记住之前勾选的数据
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- layui table表格详解
上次做table有些东西 忘记了 这次当作来个分析总结一下 跟大家共同学习 闲话不多说 直接上例子 代码: <form id="form1" runat="s ...
- 数据表格 layui.table
layui官网-表单 自动渲染 方法渲染 table.render,cols中的field是后台传递的data map.put("data",stuService.selectSt ...
- LayUI+SSM实现一个简单的后台管理系统
该后台管理系统是用于管理视频网站数据的,目前分5个菜单项,这篇博客主要讲述[影片管理]的具体功能和实现 后台代码结构和[影片管理]的界面如下图 该界面分为上下2部分,[搜索条件]和[影片列表],2部分 ...
- layui table数据表格reload where参数保留问题
layui table数据表格reload where参数保留问题 在使用layui过程中多多少少会遇到些问题 table reload 有个坑:reload时where参数会保留上次的参数,如果用 ...
- Layui table 组件的使用:初始化加载数据、数据刷新表格、传参数
背景 笔者之前一直使用 bootstrap table ,因为当前项目中主要使用 Layui 框架,于是也就随了 Layui table ,只是在使用的时候出现了一些问题,当然也是怪自己不熟悉的锅吧! ...
随机推荐
- Selenium-WebDriverApi介绍
浏览器操作: #刷新 driver.refresh() from selenium import webdriver driver=webdriver.Chrome() driver.get('htt ...
- 理解性能的奥秘——应用程序中慢,SSMS中快(4)收集解决参数嗅探问题的信息
---从计划缓存中直接获取查询计划和参数: ), ) SELECT @dbname = 'hydee_连锁', @procname = 'dbo.p_select_ware'; WITH baseda ...
- vue双向数据绑定对于数组和新增对象属性不能监听的解决办法
出现数组不能按照索引进行跟新的原因是处于性能考虑的,但是整体数组的增加删除是可以监听到的:对于对象新增属性不能监听是因为没有在生成vue实例时候放进watcher收集依赖. 首先我们先来了解vue数据 ...
- 12 October
次小生成树 http://poj.org/problem?id=1679 不难得出,次小生成树可以由最小生成树更换一条边得到. 首先构造原图的最小生成树,然后枚举每一条不在最小生成树中的边 (u, v ...
- HTML--JS 二级联动
<!doctype html> <html> <head> <meta charset="UTF-8"> <title> ...
- Apache Shiro简单介绍
1. 概念 Apache Shiro 是一个开源安全框架,提供身份验证.授权.密码学和会话管理.Shiro 框架具有直观.易用等特性,同时也能提供健壮的安全性,虽然它的功能不如 SpringSecur ...
- SpringMvc和Mybatis整合需要配置的xml
applicationContext-dao.xml <?xml version="1.0" encoding="UTF-8"?> <bean ...
- [Codeforces 1178D]Prime Graph (思维+数学)
Codeforces 1178D (思维+数学) 题面 给出正整数n(不一定是质数),构造一个边数为质数的无向连通图(无自环重边),且图的每个节点的度数为质数 分析 我们先构造一个环,每个点的度数都是 ...
- Android关于SurfaceView,SurfaceHolder,SurfaceHolder.CallBack详解
官方的定义: 1.SurfaceView SurfaceView是视图(View)的继承类,这个视图里内嵌了一个专门用于绘制的Surface.你可以控制这个Surface的格式和尺寸.Surfacev ...
- Android关于Activity生命周期详解
子曰:溫故而知新,可以為師矣.<論語> 学习技术也一样,对于技术文档或者经典的技术书籍来说,指望看一遍就完全掌握,那基本不大可能,所以我们需要经常回过头再仔细研读几遍,以领悟到作者的思想精 ...