两学一做网站登录,大连网站建设要多少钱,wordpress数据爬虫,在国外网站建设比如我们有一个订单记录管理界面
条件可以通过订单号、商品名称、创建日期范围、价格范
围。。。来进行筛选查询。
首先我们先确定数据库订单表#xff08;我这里就不做连表了#xff0c;都
放在一个表中#xff09;模拟一个订单表
order表 订单号 商品名称 创建…比如我们有一个订单记录管理界面
条件可以通过订单号、商品名称、创建日期范围、价格范
围。。。来进行筛选查询。
首先我们先确定数据库订单表我这里就不做连表了都
放在一个表中模拟一个订单表
order表 订单号 商品名称 创建日期 价格 地址 用户 121 飞机 2023-03-23 199 bj xxx 212 大炮 2023-04-23 29 bj xxx
就比如我们有一个这样的订单表 前端的话说一下思路就不做演示了我们将查询的
每个字段当作参数传递给后端我们可以通过order实
体类来接受此时要注意前端字段命名问题了但是
时间和价格都是一个范围包括开始时间-结束时间
我们实体类中没有这个字段此时我们就需要添加一
个DTO来继承那个实体类在DTO中添加这几个实体
类中没有的但是我们查询过程中会用到的字段通过
DTO来接受参数注意前端通过JSON传入后端
后端通过RequestBody接收
如果不懂怎么写的可以去看下我的这个文章前后端交互问题
如果没什么特殊的业务操作我们的业务层和控制层基本
不用写代码记得时间要格式化
实现条件查询做重要的的部分来了也就是我们的sql语句
这里我们使用mybatis的 .xml配置文件来写sql
这里sql中就用到动态拼接的方法也就是where if ....
本文实现功能只用到了这两个其他你们可以去了解
//这里的resultMapBaseResultMap可以改成resultTypeDTO类的全路径 select idselectOrder resultMapBaseResultMap
selecttipo.id, tipo.prizes_name,tipo.Receive_address_id, tipo.create_time,tipo.Audit_time,tipo.integral, tipo.user_namefromt_order tipowhere11if testprizesName ! null and prizesName ! and tip.prizes_name #{prizesName}/ifif teststartIntegral ! null and startIntegral ! if testendIntegral ! null and endIntegral ! and tip.prizes_integral between #{startIntegral} and #{endIntegral}/if/ifif testchangeStartTime ! null and changeStartTime ! if testchangeEndTime ! null and changeEndTime ! and tipo.create_time between #{changeStartTime} and #{changeEndTimestartTime}/if/if/whereorder by tipo.create_time/select
再比如:
select idselectOrder resultMapBaseResultMapselectid, prizes_name,Receive_address_id, create_time,Audit_time,integral, user_namefromt_order where11if testprizesName ! null and prizesName ! and prizes_name #{prizesName}/ifif teststartIntegral ! null and startIntegral ! if testendIntegral ! null and endIntegral ! and prizes_integral between #{startIntegral} and #{endIntegral}/if/if
//foreach的使用if testids! null and ids.length!0id INforeach itemid collectionids open( separator, close)#{id}/foreach/if/whereorder by create_time/select
上面我们就通过动态拼接实现了按多条件查询的例子啦~上面这
种也可以不通过sql直接在前端使用filter进行实现可以提高用
户体验秒速查询可以去看这个vue实现过滤器但是这种情况
不能用于数据变化频率高的情况因为在前端筛选不会重新查询数
据库也不能实时更新