stay ibatis Of xml In the document , Let's write sql sentence , corresponding mapper Class , these ones here sql Statements are no different from those on the console , However, some functions need attention , as where in
This kind of query from the array to meet the conditions of the set , Need to be in xml There's a special treatment .
<update id="batchUpdate" parameterType="map"> update customer_info set
status=#{status},appoint_time=#{appointTime} where customer_id in <foreach
collection="customerIdArr" item="customerId" index="index" open="(" close=")"
separator=","> #{customerId} </foreach> </update>
We can see that , stay xml It's going on in foreach Traversal of , An external parameter is an object of a collection or array , We are here xml Traverse it , It's more convenient .


skill : stay xml in ,parameterType Is the input parameter type , You can use it map Object ; and resultType Is the return type , If you don't have a definition DTO It can also be used map replace , although map It can make our code simple , There are, of course, flaws , It can write many weak type attribute names .