layui的数据表格+springmvc实现搜索功能的例子

今天小编就为大家分享一篇layui的数据表格+springmvc实现搜索功能的例子,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

如下所示:

主要在前端页面加:

 
搜索ID:

在js中加上:

 reload:function () { var keyWord=$("#keyWord").val(); var keyType=$("#key_type option:selected").val(); table.reload('contenttable',{ method:'post', where:{keyWord:keyWord,keyType:keyType} }); }

js的全貌:

 

通过reroad重载把参数传到springmvc后台进行模糊查询,再把查到的数据返回就好了。

其中springmvc控制层代码:

 /** * layui-content后台代码 * @return */ @RequestMapping(value = "/backContent") @ResponseBody public ResultMap> backContent(Page page, @RequestParam("limit") int limit){ page.setRows(limit); ListcontentList=contentService.selectPageList(page); int totals=contentService.selectPageCount(page); page.setTotalRecord(totals); return new ResultMap>(0,"",totals,contentList); }

因为layui返回的参数不单单是json数组,要符号其的数据格式才能在jsp页面显示数据,所以用ResultMap类来处理返回数据的格式。

 package net.stxy.one.model; /** * * layui数据表格返回数据处理类 * Created by ASUS on 2018/5/19 * * @Authod Grey Wolf */ public class ResultMap { private String msg; private T data; private int code; private int count; public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public T getData() { return data; } public void setData(T data) { this.data = data; } public int getCode() { return code; } public void setCode(int code) { this.code = code; } public int getCount() { return count; } public void setCount(int count) { this.count = count; } public ResultMap(int code,String msg, int count,T data) { this.code = code; this.msg = msg; this.count = count; this.data = data; } public ResultMap() { } } 

其中mapper的语句:

 

以上这篇layui的数据表格+springmvc实现搜索功能的例子就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持html中文网。

以上就是layui的数据表格+springmvc实现搜索功能的例子的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » JavaScript 教程