Ibatis: general configuration of sqlmap

Source: Internet
Author: User
// Compare the standard sqlmap configuration, omitting the sql-map-config.xml ..

Cebitcorpinfo. xml
<? XML version = "1.0" encoding = "UTF-8"?>
<! Doctype sqlmap
Public "-// ibatis.com//dtd SQL map 2.0 // en"
Http://www.ibatis.com/dtd/sql-map-2.dtd>
<Sqlmap namespace = "cebitcorpinfo">

<Typealias alias = "supply" type = "com. biz518.product. domain. Supply"/>
<Resultmap id = "info_map" class = "com. biz. CeBIT. domain. cebitcorpinfo">
<Result property = "ID" column = "ID"/>
<Result property = "title" column = "title"/>
<Result property = "content" column = "content" jdbctype = "clob" javatype = "Java. Lang. String"/>
<Result property = "issdate" column = "issdate"/>
<Result property = "corpid" column = "corpid"/>
</Resultmap>

<Select id = "getcebitcorpinfobyid" parameterclass = "Java. Lang. Integer" resultmap = "info_map">
Select * From cebitcorpinfo where id = # value #
</SELECT>

<Select id = "getcebitcorpinfolistbycorp" parameterclass = "Java. Lang. Integer"
Resultclass = "com. biz. CeBIT. domain. cebitcorpinfo">
Select * From cebitcorpinfo where corpid = # value #
</SELECT>

<Update id = "updatecebitcorpinfo" parameterclass = "com. biz. CeBIT. domain. cebitcorpinfo">
Update cebitcorpinfo set
<Isnotequal prepend = "" property = "ID" comparevalue = "0">
Id = # ID #
</Isnotequal>
<Isnotempty prepend = "," property = "title">
Title = # title #
</Isnotempty>
<Isnotempty prepend = "," property = "content">
Content = # content #
</Isnotempty>
<Isnotequal prepend = "," property = "corpid" comparevalue = "0">
Corpid = # corpid #
</Isnotequal>
<Isnotempty prepend = "," property = "issdate">
Issdate = # issdate #
</Isnotempty>
<Dynamic prepend = "where">
<Isnotequal prepend = "" property = "ID" comparevalue = "0">
Id = # ID #
</Isnotequal>
</Dynamic>
</Update>

<Delete id = "delcebitcorpinfobyid" parameterclass = "Java. Lang. Integer">
Delete from cebitcorpinfo where id = # value #
</Delete>

<Insert id = "insertcebitcorpinfo" parameterclass = "com. biz. CeBIT. domain. cebitcorpinfo">
<Selectkey resultclass = "int" keyproperty = "ID">
Select seq_cebitcorpinfo.nextval from dual
</Selectkey>
Insert into cebitcorpinfo (
<Isnotempty prepend = "" property = "ID">
ID
</Isnotempty>
<Isnotempty prepend = "," property = "title">
Title
</Isnotempty>
<Isnotempty prepend = "," property = "content">
Content
</Isnotempty>
<Isnotempty prepend = "," property = "corpid">
Corpid
</Isnotempty>
<Isnotempty prepend = "," property = "issdate">
Issdate
</Isnotempty>

) Values (
<Isnotempty prepend = "" property = "ID">
# ID #
</Isnotempty>
<Isnotempty prepend = "," property = "title">
# Title #
</Isnotempty>
<Isnotempty prepend = "," property = "content">
# Content #
</Isnotempty>
<Isnotempty prepend = "," property = "corpid">
# Corpid #
</Isnotempty>
<Isnotempty prepend = "," property = "issdate">
# Issdate #
</Isnotempty>
)
</Insert>

</Sqlmap>

// Typealias alias
// Parameterclass refers to the input parameter type
// When there is clob in the query result, you can use resultmap to process it (normally, resultclass = a Vo class is used directly)
// <Isnotequal prepend = "" property = "ID" comparevalue = "0"> id = # ID # </isnotequal> indicates that when this ID (property) when not equal to (isnotequal) 0 (comparevalue), add id = # ID #. prepend indicates "prefix", which indicates
// Isnotempty is similar to isnotequal, which means that isnotequal is used because ID is of the int type.
// <Dynamic prepend = "where"> when conditions are met, a where
// <Selectkey> supports automatic generation of primary keys. keyproperty = "ID" defines the primary key name.

<! -- Oracle -->
<Insert id = "insertproduct-Oracle" parameterclass = "com. domain. Product">
<Selectkey resultclass = "int" keyproperty = "ID">
Select stockidsequence. nextval as ID from dual
</Selectkey>
Insert into product (prd_id, prd_description) values (# ID #, # description #)
</Insert>

<! -- Microsoft SQL Server -->
<Insert id = "insertproduct-MS-SQL" parameterclass = "com. domain. Product">
Insert into product (prd_description) values (# description #)
<Selectkey resultclass = "int" keyproperty = "ID">
Select @ identity as ID
</Selectkey>

The insert operation of the database corresponding to the insert operation. This operation returns the primary key value of the insert record for this operation.

Select indicates the select operation of the database. This operation returns a specific pojo or object.

The update operation corresponding to the database. This operation returns the number of updated records.

Delete corresponds to the delete operation of the database. This operation returns the number of deleted records.

Procedure corresponds to the database stored procedure.

The statement type is the most common and can replace all the above types. However, it is not recommended because the operation is not intuitive.
</Insert>

// Note: When the databaseField nameAnd classAttribute nameIf it is not the same, it needs to be implicitly converted. The demo is as follows:
<Statement id = "getpoduct" resultclass = "com. iatis. example. Product">
Select
Prd_idAs ID,
Prd_descriptionAs description
From Product
Where prd_id = # value #
</Statement>

Dynamic mapped statement-iterate
Iterate attributes:
Prepend-an SQL statement that can be overwritten. (optional)
Property-elements used for traversal whose type is Java. util. List (required)
Open-string starting from the whole traversal content body, used to define parentheses (optional)
Close-the end string of the entire traversal body, used to define parentheses (optional)
Conjunction-a string between each traversal content, used to define and or (optional)

Example:
The element whose traversal type is Java. util. List.
<Iterate prepend = "and" property = "uernamelist" open = "(" Close = ")" onjunction = "or">
Username =# Usernamelist [] #
</Iterate>

// Note: When Using <iterate>, it is very important to include square brackets [] after the name of the list element. square brackets [] Mark the object as list, in case the parser simply outputs the list as a string.

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.