Length judgment and insertion method of mybatis Array and set
This article mainly introduces "mybatis array and set length judgment and insertion method". In daily operation, I believe that many people have doubts about the length judgment and insertion method of mybatis array and set. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "mybatis array and set length judgment and insertion method". Next, please follow the editor to study!
Length judgment and insertion of mybatis arrays and collections 1. It is the collection attribute that uses foreach.
This property must be specified, but the value of the property is different in different cases
There are four main situations:
If a single parameter is passed in and the parameter type is a List, the value of the collection property is list.
If a single parameter is passed in and the parameter type is a non-list Collection, the value of the collection property is collection.
If a single parameter is passed and the parameter type is an array array, the property value of collection is array
If the dao layer specifies the name of param, or if the dao layer passes the name of param or the key of map in map,collection
DefaultSqlSessionprivate Object wrapCollection (final Object object) {if (object instanceof Collection) {StrictMap map = new StrictMap (); map.put ("collection", object); if (object instanceof List) {map.put ("list", object);} return map;} else if (object! = null & object.getClass (). IsArray ()) {StrictMap map = new StrictMap (); map.put ("array", object) Return map;} return object;} 2, judge length
Collection:
Array:
Mybatis array and set judgment non-empty and length array judgment
When the parameter object is an array Object []. First determine whether it is null, and if it is not null, then you can determine whether the array length object.length is greater than 0.
Set judgment
When the parameter object is set List, you can first determine whether it is null, and if it is not null, you can determine whether the set length object.size () is greater than 0.
At this point, the study on the length judgment and insertion method of mybatis arrays and sets is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!