Mybatis Usage Details
1. mybatis encapsulates the results after SQL Execution. If no record is returned, only the encapsulated object has no value, and the object is not null;
(This problem has been neglected twice. when judging the returned Array results, I use if (Array! = Null) the result is correct. It should be if (Array. length! = 0) Determine whether the record is null)
2. In the mapper xml file, if <test = "ids. length! = 0 and ids! = Null "> here the and operation is used.
3. Data Binding
The input parameter is an integer array. The parameter in the collection is "array" and cannot be another value.
<Select id = "findSelectedItemsList" parameterType = "Integer []" resultType = "ItemsCustom"> select * from item <where> <! -- Pass the array --> <if test = "array! = Null "> <foreach collection =" array "index =" index "item =" item "open =" and id in ("separator =", "close = ") ">#{ item} </foreach> </if> </where> </select>
If the object is a pojo object with an array attribute ids, the collection parameter must be the attribute variable ids.
<insert id="createRelation" parameterType="com.xidian.ssm.po.Relation"> <if test="ids.length!=0 and ids!=null"> <foreach close="" collection="ids" index="index" item="ref_id" open="" separator=";"> insert into relation (id,ref_id) value(#{id,jdbcType=INTEGER},#{ref_id,jdbcType=INTEGER}) </foreach> </if></insert>