layui+mybatis分页,模糊查询
时间:2021-10-11
本文章向大家介绍layui+mybatis分页,模糊查询,主要包括layui+mybatis分页,模糊查询使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
1. 前端
1.1 table容器:
<table class="layui-hide" id="test"></table>
1.2 数据请求和表格渲染:
layui.use('table', function () {
var table = layui.table;
table.render({
elem: '#test',
url: '/readbarcode/getlog/',//get请求地址
cellMinWidth: 80,//自动分配宽度
cols: [[{
field: 'ipaddress',
title: 'IP地址',
align: "center"
}, {
field: 'barcode',
title: '条码号',
align: "center"
}, {
field: 'materialno',
title: '物料号',
align: "center"
}, {
field: 'userid',
title: '用户',
align: "center"
}, {
field: 'scandate',
title: '扫描日期',
align: "center",
sort: true
}, {
field: 'operationsource',
title: '来源',
align: "center"
}]],
page: true //开启分页
});
// 多条件查询
var $ = layui.$, active = {
reload: function () {
var ipaddressReload = $('#ipaddressReload');
var barcodeReload = $('#barcodeReload');
var materialnoReload = $('#materialnoReload');
var userReload = $('#userReload');
var scandateReload = $('#scandateReload');
var sourceReload = $('#sourceReload');
//执行重载
table.reload('test', {
page: {
curr: 1
//重新从第 1 页开始
},
where: {
ipaddress: ipaddressReload.val(),
barcode: barcodeReload.val(),
materialno: materialnoReload.val(),
userid: userReload.val(),
scandate: scandateReload.val(),
operationsource: sourceReload.val(),
}
});
}
};
$('.demoTable .layui-btn').on('click', function () {
var type = $(this).data('type');
active[type] ? active[type].call(this) : '';
});
});
2. 后端接口
// 获取日志列表
@RequestMapping(value = "/getlog", method = RequestMethod.GET)
@ResponseBody
public JSONObject getLog(@RequestParam("page") int page, @RequestParam("limit") int limit, @RequestParam(value = "ipaddress", required = false) String ipaddress,
@RequestParam(value = "barcode", required = false) String barcode, @RequestParam(value = "materialno", required = false) String materialno,
@RequestParam(value = "userid", required = false) String userid, @RequestParam(value = "scandate", required = false) String scandate,
@RequestParam(value = "operationsource", required = false) String operationsource)
{
JSONObject jsonObject = new JSONObject();
JSONArray jsonArray = new JSONArray();
String strDateFormat = "yyyy-MM-dd HH:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat);
try
{
List<Rbc_Querylog> logList = firstReadBarcodeService.getLogList(limit, limit * (page - 1), ipaddress, barcode, materialno, userid, scandate, operationsource);
for (Rbc_Querylog rbc_Querylog : logList)
{
JSONObject obj = new JSONObject();
obj.put("ipaddress", rbc_Querylog.getIpaddress());
obj.put("barcode", rbc_Querylog.getBarcode());
obj.put("materialno", rbc_Querylog.getMaterialno());
obj.put("userid", rbc_Querylog.getUserid());
obj.put("scandate", sdf.format(rbc_Querylog.getScandate()));
obj.put("operationsource", rbc_Querylog.getOperationsource());
jsonArray.add(obj);
}
jsonObject.put("data", jsonArray);
jsonObject.put("code", 0);
jsonObject.put("msg", "");
jsonObject.put("count", firstReadBarcodeService.getLogCount(ipaddress, barcode, materialno, userid, scandate, operationsource));
} catch (Exception e)
{
jsonObject.put("msg", "数据查询出错");
e.printStackTrace();
}
return jsonObject;
}
3. Mapper相关
3.1 方法映射
// 查询读图日志
List<Rbc_Querylog> selectLogList(@Param(value = "pagesize") int pagesize, @Param(value = "currentcount") int currentcount, String ipaddress, String barcode, String materialno, String userid,String scandate, String operationsource);
// 查询读图日志数量
int selectLogCount(String ipaddress, String barcode, String materialno, String userid, String scandate, String operationsource);
3.2 sql语句
<!-- 查询读图日志 -->
<select id="selectLogList"
resultType="com.myande.readbarcode.bean.Rbc_Querylog">
SELECT top ${pagesize} * FROM [ITM].[dbo].[rbc_querylog]
<where>
<if test="ipaddress!=null and ipaddress!=''">
ipaddress = #{ipaddress}
</if>
<if test="barcode!=null and barcode!=''">
and barcode = #{barcode}
</if>
<if test="materialno!=null and materialno!=''">
and materialno = #{materialno}
</if>
<if test="userid!=null and userid!=''">
and userid = #{userid}
</if>
<if test="scandate!=null and scandate!=''">
and DateDiff(dd,scandate,#{scandate})=0
</if>
<if test="operationsource!=null and operationsource!=''">
and operationsource = #{operationsource}
</if>
<if test="1==1">
and id not in (SELECT top ${currentcount} ID FROM
[ITM].[dbo].[rbc_querylog]
<where>
<if test="ipaddress!=null and ipaddress!=''">
ipaddress = #{ipaddress}
</if>
<if test="barcode!=null and barcode!=''">
and barcode = #{barcode}
</if>
<if test="materialno!=null and materialno!=''">
and materialno = #{materialno}
</if>
<if test="userid!=null and userid!=''">
and userid = #{userid}
</if>
<if test="scandate!=null and scandate!=''">
and DateDiff(dd,scandate,#{scandate})=0
</if>
<if test="operationsource!=null and operationsource!=''">
and operationsource = #{operationsource}
</if>
</where>
order by scandate desc)
</if>
</where>
order by scandate desc
</select>
<!-- 查询日志数量 -->
<select id="selectLogCount" resultType="int">
SELECT count(*) FROM
[ITM].[dbo].[rbc_querylog]
<where>
<if test="ipaddress!=null and ipaddress!=''">
ipaddress = #{ipaddress}
</if>
<if test="barcode!=null and barcode!=''">
and barcode = #{barcode}
</if>
<if test="materialno!=null and materialno!=''">
and materialno = #{materialno}
</if>
<if test="userid!=null and userid!=''">
and userid = #{userid}
</if>
<if test="scandate!=null and scandate!=''">
and DateDiff(dd,scandate,#{scandate})=0
</if>
<if test="operationsource!=null and operationsource!=''">
and operationsource = #{operationsource}
</if>
</where>
</select>
原文地址:https://www.cnblogs.com/yddwinter/p/15391825.html
- HTML 教程
- HTML 简介
- html div 标签介绍
- html span 标签介绍
- html a 超链接标签
- HTML Br换行标签介绍
- HTML P段落标签介绍
- HTML br与p标签区别
- Html H 标题标签
- html px em pt长度单位
- HTML form 标签
- HTML radio 单选框
- HTML B 加粗标签
- HTML strong加粗粗体标签
- HTML em 强调标签
- HTML i 斜体标签
- HTML u下划线标签
- HTML s 删除线标签
- Html img 图片标签
- Html上标注sup与下标注sub标签
- HTML nobr 禁止换行标签
- HTML hr 水平线标签
- HTML label 标签
- HTML input 标签
- HTML textarea 标签
- HTML select下拉列表标签
- HTML checkbox 多选框
- HTML font color 标签
- HTML iframe 框架标签
- HTML Table 表格
- HTML dl dt dd 标签
- HTML ol li有序列表标签
- HTML ul li 无序列表标签
- HTML 注释
- CSS 教程
- CSS 简介
- CSS 语法
- CSS Id 和 Class选择器
- CSS 样式的创建
- CSS background 背景介绍
- CSS 文本样式
- CSS font 字体
- CSS A 链接
- CSS ul ol列表样式
- CSS TABLE 样式
- CSS 框模型
- CSS border 边框
- CSS Outlines 轮廓
- CSS 外边距 Margin
- CSS Padding 内边距
- CSS 分组和嵌套选择器
- CSS 尺寸 (Dimension)
- CSS Display 属性
- CSS Position 定位
- CSS Float 浮动
- CSS 水平对齐(Horizontal Align)
- CSS 组合选择符
- CSS 伪类
- CSS 伪元素
- CSS 导航栏
- CSS 下拉菜单
- CSS 图片廊
- CSS 图像透明/不透明
- CSS sprite 图像拼合技术
- CSS 媒体类型
- CSS 属性选择器
- CSS 实例
- Dynamic Programming - 64. Minimum Path Sum
- Dynamic Programming - 322. Coin Change
- Dynamic Programming - 279. Perfect Squares
- Dynamic Programming - 120. Triangle
- Dynamic Programming - 63. Unique Paths II
- Tree - 109. Convert Sorted List to Binary Search Tree
- Tree - 108. Convert Sorted Array to Binary Search Tree Easy
- Tree - 236. Lowest Common Ancestor of a Binary Tree
- Tree - 235. Lowest Common Ancestor of a Binary Search Tree
- Tree - 98. Validate Binary Search Tree
- Tree - 199. Binary Tree Right Side View
- Tree - 103. Binary Tree Zigzag Level Order Traversal
- Tree - 107. Binary Tree Level Order Traversal II
- Trie - 212. Word Search II
- Trie - 211. Add and Search Word - Data structure design