Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to customize parameter sorting in MyBatis

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

How to customize parameter ordering in MyBatis? for this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.

MyBatis custom parameter sorting

Note (it is easy to fall into the hole):

1. Normal parameters are passed using # {} to receive parameters, such as m.grade = # {memberOrderBean.memberGrade}, but if you want to sort, you need to use the symbol ${} after order by, otherwise the sorting is invalid.

two。 When the @ Param modifier is used, the parameterType in xml does not need to be written.

Dao

/ * * member level and purchase details search (share this method) * @ author jacklin * @ since September 18, 2020 * / List searchMemberGradeDetailList (Page page, @ Param ("memberOrderBean") MemberOrderBean memberOrderBean)

Xml

SELECT m.grade memberGrade, m.pin, m.name memberName, m.phone, m.first_shopping_time, s.goods_code, s.goods_name, m.lately_buy_date, m.shop_type, m.tag, m.tops_six, m.scm_money_six, m.scm_counts orderCounts M.scm_money actualPay from member m join sc_order s on m.name = s.sc_member_name AND m.pin = # {memberOrderBean.pin} AND m.grade = # {memberOrderBean.memberGrade} AND m.name = # {memberOrderBean.memberName} AND m.phone = # {memberOrderBean.phone} AND m.tag = # {memberOrderBean.tag} AND s.goods_code = # {memberOrderBean.goodsCode} AND s.shop _ Type = # {memberOrderBean.shopType} AND m.lately_buy_date between # {memberOrderBean.latelyBuyDate_begin} and # {memberOrderBean.latelyBuyDate_end} AND s.goods_code not REGEXP 'UYCJ | UYSB | UYHC | UYBC | US | WPK | S1 | S2 | S3 | CHM' GROUP BY m.name / / Note the ${} symbol is used for sorting. And order by ${memberOrderBean.column} ${memberOrderBean.order} after GROUP BY

The sort turned out to be (incorrectly written):

Order by # {memberOrderBean.column}

It should be changed to this (the correct way to write it):

Order by ${memberOrderBean.column} the answer to the question about how to customize parameter ordering in MyBatis is shared here. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report