Mybatis+oracle adding a piece of data and returning the primary key problem for the added data

Source: Internet
Author: User

recently done Mybatis+oracle project to solve add a piece of data and return the primary key issue for the added data

Controller layer

@RequestMapping ("/addplan")    publicthrows  exception{         
//plan is the added data, Planid is the data primary key, when the primary key in the object is null int n = Service.insertonlineaddplan (plan);
//Get Object primary key System.out.println ("Return primary key value is" +Plan.getplanid ()); return plan; }

In the Mapperx.xml

 <insert id= "Insert" parametertype= "Com.online.pojo.OnlineAddplanWithBLOBs" > //gets the sequence value and assigns a value to the object's Planid field  <selectkey keyproperty= "Planid" resulttype= "DECIMAL" order= "before" > Select Online_sequence.nextval from dual  </selectkey> Insert into Online_addplan (PLANID, completetime, person, operation, USERNAME, Eventnode, workplan, Chengguo Miaoshu) 
//gets the value of the Planid field in the above object values (#{planid,jdbctype =decimal}, # {Completetime,jdbctype=timestamp}, #{person,jdbctype=varchar}, #{operation, Jdbctype =varchar}, #{username,jdbctype=varchar}, #{eventnode,jdbctype=CLOB} , #{workplan,jdbctype =clob}, #{chengguomiaoshu,jdbctype=clob}) </ Insert>

Mybatis+oracle adding a piece of data and returning the primary key problem for the added data

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.