Mybatis Usage Details

Source: Internet
Author: User

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>

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.