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 solve the problem that mybatis in query condition is too long

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

How to solve the problem of too long mybatis in query conditions, in view of this problem, this article introduces the corresponding analysis and solutions in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

Mybatis in query condition is too long solution 1: step-by-step query, split the parameters into multiple short queries and merge

Code:

Int splitNum = (int) Math.ceil ((float) ids.length/999); / / number of slices List itemIdList = new ArrayList (Arrays.asList (ids)); List splitList = averageAssign (itemIdList, splitNum); for (List list: splitList) {param.put ("itemIds", list); List itemStatisticsList = iProcessExtMapper.getItemStatisticsList (param); result.addAll (itemStatisticsList);}

The method of dividing list into N equal parts:

Public static List averageAssign (List source,int n) {List result=new ArrayList (); int remaider=source.size ()% n; / / (calculate the remainder first) int number=source.size () / n; / / then the quotient int offset=0;// offset for (int iposit i0) {value=source.subList (i*number+offset, (item1) * number+offset+1); remaider--; offset++;} else {value=source.subList (i*number+offset, (item1) * number+offset) } result.add (value);} return result;} method sqli.id in is written in the 2:xml file) OR ID IN (, # {item}

Sql logic:

The solution of ID IN (ids [0], ids [1] +... + ids [998]) OR ID IN (ids [1000],... IDS [1000]) in query with mybatis greater than 1000

The method written by a colleague in the company before:

SELECT FROM KM_DIR_DOC_LINK T WHERE T.DIR_ID IN NULL) OR T.DIR_ID IN (# {item}

However, as the amount of data increases, it is found that this method will report an error when it is greater than 2000.

The argument is as follows

Solution NULL) OR DOC.ID IN (# {item}) the answer to the question on how to solve the problem of long query conditions in mybatis in 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

Development

Wechat

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

12
Report