MyBatis course 3 and mybatis Course

Source: Internet
Author: User

MyBatis course 3 and mybatis Course

Returned auto-increment primary key values:

First, if your database supports automatic generation of primary key fields (such as MySQL)

<insert id="insertAuthor" parameterType="domain.blog.Author">  <selectKey keyProperty="id" resultType="int" order="AFTER">    select last_insert_id()</selectKey>  insert into Author    ( username, password, email,bio, favourite_section)  values    ( #{username}, #{password}, #{email}, #{bio}, #{favouriteSection,jdbcType=VARCHAR})</insert>
KeyProperty The target attribute that the selectKey statement result should be set.
ResultType The type of the result. MyBatis is can be calculated normally, but there is no problem in writing it. MyBatis allows any simple type to be used as the primary key type, including strings.
Order This can be set to BEFORE or AFTER. If it is set to BEFORE, it will first select the primary key, set the keyProperty, and then execute the insert statement. If it is set to "AFTER", execute the insert statement first, and then the selectKey element-similar to the Oracle database. You can embed sequence calls in the insert statement.

Non-auto-incrementing primary keys:

 

Related Article

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.