Ibatis Dynamic sql--<dynamic>select@ @Identity

Source: Internet
Author: User
Tags modifier

First, <dynamic><isNotNull>
<!--Select Basic Statement -    <SelectID= "Tbhyscenariosetting.select"Parameterclass= "Tbhyscenariosettingdomain"ResultClass= "Tbhyscenariosettingdomain">select ID as ID, gmt_create as gmtcreate, gmt_modified as Gmtmodified, scenario_name as S Cenarioname, Layout_type as Layouttype, industry_id as Industryid, creator as creator, Modifie        R as modifier, max_item_per_category as Maxitempercategory, Max_item_per_seller as Maxitemperseller, Max_item_per_brand as Maxitemperbrand, MAX_ITEM_PER_SPU as MAXITEMPERSPU, scene_id as Sceneid from TB hy_scenario_setting where 1=1<Dynamic>            <Isnotnull Property= "Sceneid"prepend= "and">scene_id= #sceneId #</Isnotnull>            <Isnotnull Property= "id"prepend= "and">id= #id #</Isnotnull>        </Dynamic>    </Select>
1) If the ID field is not NULL, add "and" before the Isnotnull label statement.

2) The <dynamic> tag overrides the prepend in the sub-label, and the,<dynamic> in the previous example has no prepend, so the and in the sub-label is retained.

The usage here is where 1=1, then dynamic SQL.

You can also <dynamic prepend = "where" so that you can override and in the child tag to make it where.

second, [email protected] @Identity
<!--INSERT INTO basic statement -    <InsertID= "Tbhyscenariosetting.insert"Parameterclass= "Tbhyscenariosettingdomain">INSERT INTO tbhy_scenario_setting (scene_id,gmt_create,gmt_modified,scenario_name,layout_type,industry_id, CREATOR,MODIFIER,MAX_ITEM_PER_CATEGORY,MAX_ITEM_PER_SELLER,MAX_ITEM_PER_BRAND,MAX_ITEM_PER_SPU) VALUES (#sceneId #,now (), now (), #scenarioName #, #layoutType #, #industryId #, #creator #, #modifier #, #maxItemPerCategory #,#        maxitemperseller#, #maxItemPerBrand #, #maxItemPerSpu #); <SelectkeyResultClass= "Long"Keyproperty= "id">SELECT @ @identity as ID</Selectkey>    </Insert>

Use the [email protected] @Identity to get the new record ID.

Use:

 Public Tbhyscenariosettingdomain Add (final  tbhyscenariosettingdomain domain) {        return ( Tbhyscenariosettingdomain) Transactiontemplate.execute (new  transactioncallback () {            @Override              Public Object dointransaction (transactionstatus status) {                = (Long) getsqlmapclienttemplate (). Insert (" Tbhyscenariosetting.insert ", domain);                Domain.setid (ID);                Addscenetopicsandtabs (domain);                 return domain;}}        );    }

To be Continued

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.