Mybatis -- learning notes, mybatis learning notes

Source: Internet
Author: User

Mybatis -- learning notes, mybatis learning notes

Configuration File

<Properties resource = "dbconfig. properties"> </properties>

1. properties introduces the content of the external properties configuration file

Resource: Introduce resources under the class path

Url: Introduce the network path or disk path

<Settings>

<Setting name = "mapUnderscoreToCamelCase" value = "true"/>

</Settings>

2. settings contains many important settings

Setting: Used to set each item

Name: Set the item name,

Value: set the value of an item.

<TypeAliases>

TypeAlias is an alias for a java type: Specifies the class for which the alias is to be initiated-the default alias is a class name with a small write employee alias specifying a new name

<TypeAlias type = "com. atguigu. mybatis. bean. Employee" alias = "emp"/>

A package is an alias for all classes in a package.

Name: Specifies the package name (a default alias (lower case) for the current package and no classes in the future package ))

<Package name = "com. atguigu. mybatis. bean"/>

When aliases are batch initiated, use the @ Alias annotation to specify a new Alias for a class.

</TypeAliases>

3. The typeAliases alias processor can alias our java class

(Aliases are case insensitive)

<Environments default = "development">

<Environment id = "development">

<TransactionManager type = "JDBC"/>

<DataSource type = "POOLED">

<Property name = "driver" value = "$ {jdbc. driver}"/>

<Property name = "url" value = "$ {jdbc. url}"/>

<Property name = "username" value = "$ {jdbc. username}"/>

<Property name = "password" value = "$ {jdbc. password}"/>

</DataSource>

</Environment>

</Environments>

4. environments, mybatis can be configured in multiple environments. default specifies a certain environment, which allows you to quickly switch between environment and configure a specific environment information,

There must be two tags. id indicates the unique identifier of the current environment. transactionManager Transaction Manager type dataSource Data Source

<DatabaseIdProvider type = "DB_VENDOR">

<! -- Alias for different database vendors -->

<Property name = "MySQL" value = "mysql"/>

<Property name = "Oracle" value = "oracle"/>

<Property name = "SQL Server" value = "sqlserver"/>

</DatabaseIdProvider>

5. databaseIdProvider supports

Type = "DB_VENDOR" indicates the ID of the database vendor. mybatis executes different SQL statements based on the ID of the database vendor.

<! -- Register the prepared SQL ing file to the global configuration file. -->

<! -- Mappers registers the SQL ing to the global configuration -->

<Mappers>

<! --

Mapper registers an SQL ing

Resource reference class path

Url reference network path

Class: Reference (Registration) Interface

1. the SQL ing file name of an SQL ing file must be in the same directory as the interface.

2. There is no SQL ing file. All SQL statements are written on the interface using annotations.

-->

<! -- <Mapper resource = "mybatis/mapper/EmployeeMapper. xml"/> -->

<! -- <Mapper class = "com. atguigu. mybatis. dao. EmployeeMapperAnnotation"/> -->

<! -- Batch registration -->

<Package name = "com. atguigu. mybatis. dao"/>

</Mappers>

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.