Ibatis.net Series (iii)-sqlmap.config

Source: Internet
Author: User

The Sqlmap.config file is the core of the entire Ibatis framework and can be seen from his name.
When we call the Ibatisnet framework to access the database, It will automatically go to the root of the project to find the Sqlmap.config file, so the path of this file will be placed in the same directory as the Web. config, and the file name cannot be modified, if it is not the root of the project or file name is incorrect, then you need to parse the file when you call.
This file has a lot of configuration nodes, when the Ibatis framework starts to parse each node in this file, to play the entire framework from these configuration nodes to start, the next one to describe the purpose of each node
1 alias node--configures the aliases that can be used by the entire framework
Examples:
<alias>
<typealias alias= "Student" type= "Ibnetmodel.student"/>
</alias>
With this configuration, you can use the alias student in the entire configuration file to represent the Ibnetmodel.student object.
2 Properties Node--for the introduction of additional data files
Example: <properties resource= "Properties.config"/>
With this configuration, the Ibatis framework parses the Properties.config configuration file and then references the data in the configuration file in the same way as ${name}. General bar The database connection string, the database driver writes to this file, and then the reference, which is described later.
3 Settings node--used to set the entire Ibatis frame
Examples:
<settings>
<setting usestatementnamespaces= "false"/>
<setting cachemodelsenabled= "false"/>
<setting validatesqlmap= "false"/>
</settings>
1) <setting usestatementnamespaces= "false"/>
The Usestatementnamespaces property sets whether to use the fully qualified name when calling Ibatis's SQL statement.
2) <setting cachemodelsenabled= "false"/>
The Cachemodelsenabled property to set the global cache switch, which is discussed later
3) <setting validatesqlmap= "false"/>
This configuration does not know what meaning?? Does the document describe whether Sqlmapconfig.xsd is enabled to validate the mapping XML file, and is set to TRUE or false what is the difference?
4 providers node--used to set the path of the database driver file
Examples:
<providers resource= "Providers.config"/>
The Ibatis framework parses the contents of the Providers.config file under the current path as a database driver, Ibatis.datamapper.1.6.2.bin This folder contains sample files, when the name of the file is Providers.config, and the path follows the SQL Map.config The configuration node can be omitted at the same time.
5 Database node--used to define the databases used by the entire Ibatis framework
Examples:
<database>
<provider name= "sqlServer4.0"/>
<datasource name= "Home" connectionstring= "Data source=127.0.0.1;initial catalog=db2; User Id=sa; Password=123 "/>
</database>
Where name=sqlserver4.0 is the driver that references the name sqlServer4.0 in the Providers.config file.
DataSource node name can be arbitrarily up, ConnectionString is the database connection string (which will be placed in Properties.config later)
6 sqlmaps Node--Enumerate all data map files, i.e. files that hold SQL statements
Examples:
<sqlMaps>
<sqlmap resource= ". /ibnetmodel/maps/student.xml "/>
<sqlmap resource= ". /ibnetmodel/maps/course.xml "/>
</sqlMaps>
Where the Student.xml,course.xml two data map files in the Ibnetmodel project's Maps folder, so you have to specify the path, so that the program will know the path of the mapping file (then the path is stored in the Properties.config)

According to my experience, these configuration nodes are ordered, and the order is incorrect.
Finally, post a sample configuration of the overall Sqlmap.config file
<?xml version= "1.0" encoding= "Utf-8"?>
<sqlmapconfig xmlns= "Http://ibatis.apache.org/dataMapper"
xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" >
<properties resource= "Properties.config"/>
<settings>
<setting usestatementnamespaces= "false"/>
<setting cachemodelsenabled= "false"/>
<setting validatesqlmap= "false"/>
</settings>
<database>
<provider name= "sqlServer4.0"/>
<datasource name= "Home" connectionstring= "Data source=127.0.0.1;initial catalog=db2; User Id=sa; Password=123 "/>
</database>
<sqlMaps>
<sqlmap resource= ". /ibnetmodel/maps/student.xml "/>
<sqlmap resource= ". /ibnetmodel/maps/course.xml "/>
</sqlMaps>
</sqlMapConfig>

Ibatis.net Series (iii)-sqlmap.config

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.