大型集团公司网站建设方案,微信公众号api接口,响应式设计网站案例,智慧旅游网站建设方案ppt比如我们有一个订单记录管理界面
条件可以通过订单号、商品名称、创建日期范围、价格范围。。。来进行筛选查询。
首先我们先确定数据库订单表#xff08;我这里就不做连表了#xff0c;都放在一个表中#xff09;模拟一个订单表
order表
订单号商品名称创建日期价格地址…比如我们有一个订单记录管理界面
条件可以通过订单号、商品名称、创建日期范围、价格范围。。。来进行筛选查询。
首先我们先确定数据库订单表我这里就不做连表了都放在一个表中模拟一个订单表
order表
订单号商品名称创建日期价格地址用户121飞机2023-03-23199bjxxx212大炮2023-04-2329bjxxx
就比如我们有一个这样的订单表
前端的话说一下思路就不做演示了我们将查询的每个字段当作参数传递给后端我们可以通过order实体类来接受此时要注意前端字段命名问题了但是时间和价格都是一个范围包括开始时间-结束时间我们实体类中没有这个字段此时我们就需要添加一个DTO来继承那个实体类在DTO中添加这几个实体类中没有的但是我们查询过程中会用到的字段通过DTO来接受参数注意前端通过JSON传入后端后端通过RequestBody接收
如果不懂怎么写的可以去看下我的这个文章前后端交互问题
如果没什么特殊的业务操作我们的业务层和控制层基本不用写代码记得时间要格式化
实现条件查询做重要的的部分来了也就是我们的sql语句
这里我们使用mybatis的 .xml配置文件来写sql
这里sql中就用到动态拼接的方法也就是where if ....
本文实现功能只用到了这两个其他你们可以去了解
//这里的resultMapBaseResultMap可以改成resultTypeDTO类的全路径
select idselectOrder resultMapBaseResultMap select tipo.id, tipo.prizes_name,tipo.Receive_address_id, tipo.create_time, tipo.Audit_time, tipo.integral, tipo.user_name from t_order tipo where 11 if testprizesName ! null and prizesName ! and tip.prizes_name #{prizesName} /if if teststartIntegral ! null and startIntegral ! if testendIntegral ! null and endIntegral ! and tip.prizes_integral between #{startIntegral} and #{endIntegral} /if /if if testchangeStartTime ! null and changeStartTime ! if testchangeEndTime ! null and changeEndTime ! and tipo.create_time between #{changeStartTime} and #{changeEndTimestartTime} /if /if /where order by tipo.create_time /select
上面我们就通过动态拼接实现了按多条件查询的例子啦~上面这种也可以不通过sql直接在前端使用filter进行实现可以提高用户体验秒速查询可以去看这个vue实现过滤器