Java Framework mybaits Core configuration

Source: Internet
Author: User
Tags naming convention

One: Mybaits core configuration file: Sqlmapconfig.xml

Properties that need to be followed in the configuration file:

Second, properites properties : General reference configuration file (properites file) such as: Database configuration. We can write a db.properites file. By loading the Sqlmapconfig.xml file, first reading the resource value in the Properites property to read the configuration contents of the Properites and load the property and property values into memory, he overwrites the property with the same name previously loaded.

Db.properites

1 jdbc.driver=com.mysql.jdbc.Driver2 jdbc.url=jdbc:mysql://localhost : 3306/day_spring?characterencoding=utf-83 jdbc.username=root4 jdbc.password=root

Properites Tags:

1 <properties resource="db.properites" />

Sqlmapconfig.xml supports El Expressions: Avoids hard coding of configuration information.

1<datasource type="Pooled">2<property name="Driver"Value="${jdbc.driver}"/>3<property name="URL"Value="${jdbc.url}"/>4<property name="username"Value="${jdbc.username}"/>5<property name="Password"Value="${jdbc.password}"/>6</dataSource>

Third,typealiases type alias:

1 types of alias mappings2_bytebyte 3_longLong 4_short Short 5_intint 6_integerint 7_doubleDouble 8_floatfloat 9 _boolean BooleanTen stringString One byteByte A LongLong -  Short Short - intInteger the integer integer - DoubleDouble - floatFloat - Boolean Boolean + Date Date - decimalBigDecimal + BigDecimal BigDecimal AMap map

These properties allow us to use aliases in the child configuration file.

We can also add aliases to our classes: Note that they are configured in Sqlmapconfig.xml

1) Configure aliases for individual classes:

1     <typeAliases>2         <typealias type="jd.com.mybaitstest.account" alias="account" />3     </typeAliases>

Type is the class referenced in the child configuration file. Alias is a nickname. This is only for individual. If there are many classes in the package, this is the time to use the Packages property.

2) When configuring aliases for multiple classes:

1     <typeAliases>2         <!--<typealias type="jd.com.mybaitstest.account" alias="account" />-->3         <package name="  Jd.com.mybaitstest" />4     

Attention:

The property value of the package here is the full path of the packet, the rule of the alias:

1) aliases are the same as class names.

2) Aliases are not case-sensitive, but generally follow the Java naming convention: The first letter lowercase, the first letter of the following word, the camel's name.

Be aware of the label:<typealiases> in the label <properties> below.

Four, mapper mapper :

1) Resource way:

1 <mapper resource="account.xml" />

2) class mode:

1 class="jd.com.proxydao.AccMapper" />

Specification Requirements:

1:mapper files and interfaces need to be under the same package.

The name of the 2:mapper mapping file needs to be the same as the name of the interface file except for the extension.

3) package scanner mode. Benefit: If there are many mapper files under the package, you do not need to write more than one.

1 <package name="jd.com.proxydao"  />

The standard requirements are the same as the Clas method.

1:mapper files and interfaces need to be under the same package.

The name of the 2:mapper mapping file needs to be the same as the name of the interface file except for the extension.

Full Sqlmapconfig.xml file content:

1<?xml version="1.0"encoding="UTF-8"?>2<!DOCTYPE Configuration3Public"-//mybatis.org//dtd Config 3.0//en"4         "HTTP://MYBATIS.ORG/DTD/MYBATIS-3-CONFIG.DTD">5 6 7<configuration>8<properties resource="db.properites"/>9<!--and spring are integrated after the environments configuration will be abolished--Ten<typeAliases> One<!--<typealias type="Jd.com.mybaitstest.account"alias=" Account"/>--> A<package name="jd.com.mybaitstest"/> -</typeAliases> -<environmentsdefault="Development"> the<environment id="Development"> -<!--using JDBC Transaction Management-- -<transactionmanager type="JDBC"/> -<!--database connection pool Mybaits The connection pool that comes with-- +<datasource type="Pooled"> -<property name="Driver"Value="${jdbc.driver}"/> +<property name="URL"Value="${jdbc.url}"/> A<property name="username"Value="${jdbc.username}"/> at<property name="Password"Value="${jdbc.password}"/> -</dataSource> -</environment> -</environments> -<mappers > -<!--<mapper resource="Account.xml"/>--> in  -<!--<mapperclass="Jd.com.proxydao.AccMapper"/>--> to<package name="Jd.com.proxydao"/> +</mappers> -</configuration>

Java Framework mybaits Core configuration

Related Article

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.