SQL usage for MyBatis (configuration of mapper mapping file)

Source: Internet
Author: User

I. Principles of MAPPER Agent development

Requires the namespace attribute value in the mapper mapping file, which must be the fully qualified name of the Mapper proxy interface

Requires a declaration of the SQL statement label in the Mapper mapping file, consistent with the declaration of the Mapper interface method (method with the same name)

Requires the type specified by the Resulttype property of the SQL statement (if the return value is a collection, resulttype specifies the type stored in the collection), and the return value type of the Mapper interface method is the same

Requires the id attribute value of the SQL statement, consistent with the method name of the Mapper interface

Requires the type specified by the ParameterType property of the SQL statement, consistent with the parameter type of the Mapper interface method

1. Increase operation

<insert id="Insertuser" parametertype="Com.code.po.User">

Insert INTO ' user ' (ID,username, birthday,sex,address)

VALUES (#{id},#{username},#{birthday},#{sex},#{address})//The property here should correspond to the previous

</insert>

2. Get primary key values for database maintenance (only available when you just insert)

<!--before?oracle Database Usage--

<selectkey keycolumn= "id" keyproperty= "id" resulttype= "int" order= "before" >

Select Seq.nextval from dual

</selectKey>

<!--after?oracle Database Usage--

<selectkey keycolumn="id" keyproperty="id " resulttype="int" order="after" >

Select LAST_INSERT_ID ()

</selectKey>

3. modifying data by ID

<update id="Updateuserbyid" parametertype="com.code. Po. User ">

Update ' user '

Set username=#{username},sex=#{sex} where Id=#{id}

</update>

4. Delete data by ID

<delete id="Deleteuserbyid" parametertype="int">

Delete from ' user ' where Id=#{id}

</delete>

SQL usage for MyBatis (configuration of mapper mapping file)

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.