Ibatis learning-sqlmap. xml configuration file

Source: Internet
Author: User

From http://flatfish2000.iteye.com/blog/561985

 

Ibatis ing file writing:

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <! Doctype sqlmap <br/> Public "-// ibatis.com//dtd SQL map 2.0/EN" <br/> "http://www.ibatis.com/dtd/sql-map-2.dtd"> <br/> <sqlmap namespace = "user"> <br/> <! -- Define the cache mechanism of the ing file --> <br/> <cachemodel type = "LRU" id = "usercache"> <br/> <! -- Set the cache survival time --> <br/> <flushinterval hours = "24"/> <br/> <! -- Set the specified operation and clear the cache --> <br/> <flushonexecute Statement = "updateuser"/> <br/> <! -- Set the cache capacity (object) --> <br/> <property name = "size" value = "1000"/> <br/> </cachemodel> <br/> <! -- Define an alias --> <br/> <typealias alias = "user" type = "com. wyq. pojo. User"/> <br/> <! -- Improves query efficiency through caching --> <br/> <select id = "getusers" <br/> parameterclass = "Java. lang. integer "<br/> resultclass =" user "cachemodel =" usercache "> <br/> <! -- Use! [DATA [] format to avoid the legality of SQL-heavy characters and XML ing files --> <br/> <! -- [CDATA [<br/> select ID, name, sex from t_user <br/>]> <br/> </SELECT> <br/> <update id = "updateuser" parameterclass = "user"> <br/> <! [CDATA [<br/> Update t_user set name = # name #, sex = # Sex # Where id = # ID # <br/>] --> <br/> </update> <br/> <insert id = "insertuser" parameterclass = "user"> <br/> insert into t_user (name, sex) values (# name #, # Sex #) <br/> </Insert> <br/> <Delete id = "deleteuser" parameterclass = "Java. lang. string "> <br/> Delete from t_user where id = # value # <br/> </delete> <br/> </sqlmap> </P> <p> <statement id = "statementname" <br/> [Parameterclass = "some. class. name "] // indicates that the input parameter type is class <br/> [resultclass =" some. class. name "] // indicates that the output parameter type is class <br/> [parametermap =" nameofparametermap "] // indicates that the input parameter type is Map <br/> [resultmap =" nameofresultmap "] // indicates that the output parameter type is class <br/> [cachemodel =" nameofcache "] <br/> select * From t_user where sex = [? | # Propertyname #] <br/> order by [$ simpledynamic $] <br/> </Statement>

 

1. for Parameter definition, try to use parameterclass, that is, directly use pojo as the statement call parameter. If the input parameter is Java. util. map, then the key value in the map will be used as the input parameter. The common basic type is direct input.

2. If possible, use resultclass to directly match the field name with pojo.

3. While parametermap and resultmap implement the poing configuration from pojo to database fields, parametermap is rarely used, while resultmap is mostly used for nested queries and stored procedures.

<Resultmap id = "get_user_result" class = "user"> <br/> <result property = "name" column = "Xingming" jdbctype = "varchar" javatype = "Java. lang. string "/> <br/> <result property =" sex "column =" xingbie "jdbctype =" int "javatype =" Java. lang. integer "/> <br/> <result property =" ID "column =" ID "jdbctype =" int "javatype =" Java. lang. integer "/> <br/> </resultmap> <br/> <parametermap id =" update_user_para "class =" Redemption "> <br/> <parameter property =" name" jdbctype = "varchar" javatype = "Java. lang. string "nullvalue =" "/> <br/> <parameter property =" sex "jdbctype =" int "javatype =" Java. lang. integer "nullvalue =" "/> <br/> </parametermap> <br/> <procedure id =" getuserlist "resultmap =" get_user_result "> <br/> {call sp_getuserlist ()} <br/> </procedure> <br/> <procedure id = "douserupdate" parametermap = "update_user_para"> <br/> {call sp_douserupdate (# ID #, # name #, # Sex #)} <br/> </procedure>

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.