1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > layui自定义查询条件html页面 Layui的数据表格+springmvc实现搜索功能的例子_飛雲_前端开发者...

layui自定义查询条件html页面 Layui的数据表格+springmvc实现搜索功能的例子_飛雲_前端开发者...

时间:2024-07-12 11:13:27

相关推荐

layui自定义查询条件html页面 Layui的数据表格+springmvc实现搜索功能的例子_飛雲_前端开发者...

如下所示:

主要在前端页面加:

搜索ID:

userid

content

搜索

reload:function () {

var keyWord=$("#keyWord").val();

var keyType=$("#key_type option:selected").val();

table.reload('contenttable',{

method:'post',

where:{keyWord:keyWord,keyType:keyType}

});

}

layui.use('table', function(){

var table = layui.table;

//渲染

table.render({

elem: '#test' //绑定table表格

,height: 450

,url: '/admin/backContent' //后台springmvc接收路径

,page:true //true表示分页

,limit: 10

,id:'contenttable'

,toolbar: '#toolbarDemo'

,cols: [[

{type: 'checkbox', fixed: 'left'}

,{field:'id', title:'id', width:80, fixed: 'left', unresize: true, sort: true}

,{field:'content', title:'内容', width:120}

,{field:'userid', title:'用户id', width:80, sort: true}

,{field:'nice', title:'点赞数', width:100}

,{field:'createtime', title:'分享时间', width:80, sort: true}

,{field:'pic1', title:'图片1', width:120,templet:'

@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 /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的语句:

select

from content

AND userid like '%' #{keyWord} '%'

AND content like '%' #{keyWord} '%'

order by id DESC

limit #{start},#{rows}

select count(1) from content

AND userid like '%' #{keyWord} '%'

AND content like '%' #{keyWord} '%'

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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。