Mybatis应用mysql存储过程查询数据的示例分析
小编给大家分享一下Mybatis应用MySQL存储过程查询数据的示例分析,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
十载的双塔网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。成都全网营销的优势是能够根据用户设备显示端的尺寸不同,自动调整双塔建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联从事“双塔网站设计”,“双塔网站推广”以来,每个客户项目都认真落实执行。
1.创建mysql存储过程,这是个复杂查询加上了判断,比较复杂
CREATE PROCEDURE searchAllList ( IN tradingAreaId VARCHAR (50), IN categoryName VARCHAR (100), IN intelligenceSort TINYINT UNSIGNED, IN priceBegin DOUBLE, IN priceEnd DOUBLE, IN commodityName VARCHAR (200), IN flag TINYINT UNSIGNED ) BEGIN IF flag = 0 THEN SELECT B.user_business_id businessId, B.shop_name, B.total_score, B.shop_logo, B.average_consume, D.category_name, B.shop_address FROM user_business_commodity A LEFT JOIN user_business B ON B.user_business_id = A.user_business_id LEFT JOIN user_business_category C ON C.business_id = B.user_business_id LEFT JOIN service_category D ON D.category_id = C.category_one_id WHERE 1 = 1 AND IF ( categoryName IS NOT NULL AND LENGTH(TRIM(categoryName)) > 0, D.category_name = categoryName, 1 = 1 ) AND IF ( priceBegin != 0, B.average_consume >= priceBegin, 1 = 1 ) AND IF ( priceEnd != 0, B.average_consume <= priceEnd, 1 = 1 ) AND IF ( commodityName IS NOT NULL AND LENGTH(TRIM(commodityName)) > 0, A. NAME LIKE concat('%', commodityName, '%'), 1 = 1 ) AND B.is_delete = 0 AND B.shop_setup_state = 1 AND A.is_delete = 0 AND C.is_delete = 0 AND D.is_delete = 0 GROUP BY A.user_business_id ORDER BY CASE intelligenceSort WHEN 1 THEN 'B.total_order DESC' WHEN 2 THEN 'B.total_score DESC' WHEN 3 THEN 'B.create_time DESC' ELSE 'B.create_time ASC' END; ELSE SELECT B.user_business_id businessId, B.shop_name, B.total_score, B.shop_logo, B.average_consume, D.category_name, B.shop_address FROM user_business_commodity A LEFT JOIN user_business B ON B.user_business_id = A.user_business_id LEFT JOIN user_business_category C ON C.business_id = B.user_business_id LEFT JOIN service_category D ON D.category_id = C.category_two_id WHERE 1 = 1 AND IF ( categoryName IS NOT NULL AND LENGTH(TRIM(categoryName)) > 0, D.category_name = categoryName, 1 = 1 ) AND IF ( priceBegin != 0, B.average_consume >= priceBegin, 1 = 1 ) AND IF ( priceEnd != 0, B.average_consume <= priceEnd, 1 = 1 ) AND IF ( commodityName IS NOT NULL AND LENGTH(TRIM(commodityName)) > 0, A. NAME LIKE concat('%', commodityName, '%'), 1 = 1 ) AND B.is_delete = 0 AND B.shop_setup_state = 1 AND A.is_delete = 0 AND C.is_delete = 0 AND D.is_delete = 0 GROUP BY A.user_business_id ORDER BY CASE intelligenceSort WHEN 1 THEN 'B.total_order DESC' WHEN 2 THEN 'B.total_score DESC' WHEN 3 THEN 'B.create_time DESC' ELSE 'B.create_time ASC' END; END IF; END;
2.查看存储过程是否创建成功:
show procedure status;
3.sqlMapper文件:
其他和直接调用sql语句一样了
以上是“Mybatis应用mysql存储过程查询数据的示例分析”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联行业资讯频道!
网站名称:Mybatis应用mysql存储过程查询数据的示例分析
本文URL:http://scjbc.cn/article/jjeiec.html