Ibatisnet Study Notes 1: Configuration

Source: Internet
Author: User
Tags connection reset

Download an ibatisnet demo from the Internet andArticleUnderstanding and learning.

Demo configuration files include sqlmap. config, database. config, providers. config, Web. config, and person. xml.

Follow these steps:

References:

Http://www.cnblogs.com/pw/archive/2006/08/08/470060.html

First, understand sqlmap. config

Ibatisnet datamapper is configured through an XML file. The configuration file name is usually sqlmap by default. config. The configuration file specifies the database connection string of our project and the ing file of the database table.

Sqlmap. config file:

 

Sqlmap. config

<? XML version = "1.0" encoding = "UTF-8" ?>
< Sqlmapconfig Xmlns = "Http://ibatis.apache.org/dataMapper" Xmlns: xsi = "Http://www.w3.org/2001/XMLSchema-instance"   >

<! -- Rem: if used via a dataaccess context, properties tag will be ignored
<Properties resource = "http://www.cnblogs.com/database.config"/> -->
< Properties Embedded = "Database. config, ibatisnetdemo" />
< Settings >
< Setting Usestatementnamespaces = "$ {Usestatementnamespaces }" />
< Setting Cachemodelsenabled = "True" />
< Setting Validatesqlmap = "False" />
</ Settings >

<! -- Optional if Resource -->
< Providers Embedded = "Providers. config, ibatisnetdemo" />
<! -- ===== Sqlclient configuration ========== -->
<! -- Rem: if used via a dataaccess context, database tag will be ignored -->
< Database >
<! -- Optional (default) -->
< Provider Name = "Sqlserver2.0" />
< Datasource Name = "Ibatisnet" Connectionstring = "Data Source =$ {datasource}; database =$ {database}; User ID =$ {userid}; password =$ {password}; Connection Reset = false; connection lifetime = 5; min pool size = 1; Max pool size = 50" />
</ Database >

< Sqlmaps >
<! -- User via embedded -->
< Sqlmap Embedded = "Map. sqlclient. Person. XML, ibatisnetdemo" />
</ Sqlmaps >
</ Sqlmapconfig >

 

 

Explanation:

1. properites

<Properties embedded = "database. config, ibatisnetdemo"/> specify the properties FileProgramSet resource files to load

2. Setting

Whether usestatementnamespaces uses the satement namespace. The namespace here refers to the namespace attribute of the sqlmap node in the ing file.

The person ing file person. xml: <sqlmap namespace = "person" xmlns = "http://ibatis.apache.org/mapping"
Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance">
Does cachemodelsenabled enable the datamapper cache mechanism for all sqlmaps (what is the cache mechanism of datamap ?)

Validatesqlmap whether to enable sqlmapconfig. XSD Schema verification ing File

3. Providers
Used to provide the file name and path of the database driver configuration file

<Providers embedded = "providers. config, ibatisnetdemo"/>

4. Database

It includes two child elements: provider and datasource.
If the default database driver is specified in the providers. config file, the provider node does not need to be set. It does not need to modify the providers. config file when changing the database driver. Datasource node is used to specify ADO. net connection string.
<Database>
<! -- Optional (default) -->
<Provider name = "sqlserver2.0"/>
<Datasource name = "ibatisnet" connectionstring = "Data Source =$ {datasource}; database =$ {database}; User ID =$ {userid}; password =$ {password }; connection Reset = false; connection lifetime = 5; min pool size = 1; Max pool size = 50 "/>
</Database>

5. sqlmap

Datamapper instances used by all applications must be listed under this node, that is, the ing file.
<Sqlmap embedded = "map. sqlclient. Person. XML, ibatisnetdemo"/>

The $ variable is configured in database. config and loaded through <properties embedded = "database. config, ibatisnetdemo"/>.

Database. config file:

Database. config

<? XML version = "1.0" encoding = "UTF-8" ?>
< Databaseconfig Xmlns = "Http://ibatis.apache.org/dataMapper" Xmlns: xsi = "Http://www.w3.org/2001/XMLSchema-instance"   >
< Settings >
< Add Key = "Userid" Value = "Sa"   />
< Add Key = "Password" Value = "1234"   />
< Add Key = "Database" Value = "Ibatis"   />
< Add Key = "Datasource" Value = "(Local )"   />
< Add Key = "Selectkey" Value = "Select @ identity as value"   />
< Add Key = "Directory" Value = "Maps"   />
< Add Key = "Usestatementnamespaces" Value = "False"   />
</ Settings >
</ Databaseconfig >

 

You can also directly write database parameters in the sqlmap. config file without the database. config file.

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.