ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

layui+mybatis分页,模糊查询

2021-10-11 09:35:58  阅读:197  来源: 互联网

标签:operationsource 分页 layui barcode userid materialno String mybatis scandate


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>

标签:operationsource,分页,layui,barcode,userid,materialno,String,mybatis,scandate
来源: https://www.cnblogs.com/yddwinter/p/15391825.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有