11_ about Sqlmapperconfig.xml

Source: Internet
Author: User

Brief

Sqlmapconfig.xml is the global configuration file for MyBatis with the following configuration:

1.properties---------Properties

2.settings-----------Global configuration parameters

3.typeAliases--------Type aliases

4.typeHandlers------Type Processor

5.objectFactory-----Object Factory

6.plugins------------Plug-in

7.environments-----Environment Collection Property Object

Environments---------Environment Sub-Property object

TransactionManager----------Transaction Management

DataSource-------------------Data source

8.mappers---------Mapper

(1)Properties Property

Demand:

To configure the connection parameters in the database separately in db.properties, you only need to load the Db.properties configuration file in Sqlmapconfig.xml.

You do not need to hard-code database connection parameters in Sqlmapconfig.xml.

Advantages of configuration in Db.properties: Convenient for unified management of parameters, other XML files can refer to the Db.properties

The original "Sqlmapconfig.xml" database is related to the following configuration:

After modifying the "Sqlmapconfig.xml" below, be careful not to forget <properties resource= "db.properties" ></ Properties>

After you modify the contents of the "db.properties" configuration file as follows

"Order of MyBatis Load Properties"

1. Attributes that are set in the properties element are first loaded.

2. The properties that are loaded with the resource or URL in the property element are then read, overwriting attributes that have already been read (so name to note)

3. Finally, the properties passed by the ParameterType are read, overwriting properties that have been read with the same name.

Note

Do not add any attribute values to the body of the <properties> element, only the attribute values are defined in the Db.properties file.

Defining a property file name in the Db.properties file should be specific, such as Jdbc.xxx.xxx

(2) settings global parameter configuration

MyBatis Framework can adjust some running parameters at run time

For example: Turn on level Two cache, turn on lazy loading ....

(3) Typealiases (alias) (Learn the key!) )

Demand:

In Mapper.xml, a lot of statement are defined.

"Default of some aliases of the source code"

Registeralias ("string", String.class); Registeralias ("Byte", byte.class); Registeralias ("Long", long.class); Registeralias ("Short", short.class); Registeralias ( "int", Integer. class ); Registeralias ("integer", integer. class ); It can be found thatparameter= "int" or parametertype= "integer" will eventually point to an integer  Registeralias ("Double", double.class); Registeralias ("Float", float.class); Registeralias ("Boolean", Boolean.class); Registeralias ("byte[]", byte[].class); Registeralias ("long[]", long[].class); Registeralias ("short[]", short[].class); Registeralias ("int[]", integer[].class); Registeralias ("integer[]", integer[].class); Registeralias ("double[]", double[].class); Registeralias ("float[]", float[].class); Registeralias ("boolean[]", boolean[].class); Registeralias ("_byte",byte.class); Registeralias ("_long",Long.class); Registeralias ("_short", Short.class); Registeralias ("_int",int.class); Registeralias ("_integer",int.class); Registeralias ("_double",Double.class); Registeralias ("_float",float.class); Registeralias ("_boolean",Boolean.class); Registeralias ("_byte[]",byte[].class); Registeralias ("_long[]",Long[].class); Registeralias ("_short[]", Short[].class); Registeralias ("_int[]",int[].class); Registeralias ("_integer[]",int[].class); Registeralias ("_double[]",Double[].class); Registeralias ("_float[]",float[].class); Registeralias ("_boolean[]",Boolean[].class); Registeralias ("Date", date.class); Registeralias ("Decimal", BigDecimal.class); Registeralias ("BigDecimal", BigDecimal.class); Registeralias ("BigInteger", BigInteger.class); Registeralias ("Object", object.class); Registeralias ("date[]", date[].class); Registeralias ("decimal[]", bigdecimal[].class); Registeralias ("bigdecimal[]", bigdecimal[].class); Registeralias ("biginteger[]", biginteger[].class); Registeralias ("object[]", object[].class); Registeralias ("Map", map.class); Registeralias ("HashMap", HashMap.class); Registeralias ("List", list.class); Registeralias ("ArrayList", ArrayList.class); Registeralias ("Collection", collection.class); Registeralias ("Iterator", iterator.class); Registeralias ("ResultSet", ResultSet.class);

"Aliases for Pojo types that you define"

In "Sqlmapper.xml", the definition for a single alias

In "Sqlmapper.xml", the definition for the bulk alias ( batch method is more common )

Specifies the package name, MyBatis automatically scans the Pojo class in the package, automatically defines the alias, which is the class name (the first letter is case-sensitive)

(4) Typehandlers (type processor)

The conversion of JDBC type and Java type is done through typehandlers in MyBatis.

Typically, MyBatis provides a type processor that meets everyday needs without customization.

(5) Mappers (map configuration)

1. How to load a single mapping file through resource in the example "Sqlmapconfig.xml":

2. Loading a single mapping file via the Mapper interface

There are some specifications to follow: you need to keep the Xxxmapper.java and xxxmapper.xml mapping filenames consistent and in one directory .

Upper specification premise: Using the Mapper proxy method

3. Bulk Load

Bulk load the package name of the Mapper interface. MyBatis automatically scans all the mapper interfaces underneath the package for loading

Specifications to follow: you need to keep the Xxxmapper.java and xxxmapper.xml mapping filenames consistent and in one directory .

Upper specification premise: Using the Mapper proxy method

11_ about Sqlmapperconfig.xml

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.