Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve the problem that mybatis in query condition is too long

Shulou Source: shulou.com Published: 2022-06-03 07:18:54 09月17日 Update

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.

Tags: Methods queries questions conditions more help answers easy easy code remainder company content method parameters colleagues multiple guys buddies data Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Shulou Technology Xiaomi vpn Microsoft