I used Idea's IDE environment. To create xml more easily and quickly using mybatis framework, I created templates in my IDE environment.
Specific template creation can be viewed by clicking on the following link: ----> to be added later
Under the resource folder, create the configuration xml file - > mybatis. cfg. xml
Configuration: This is the root node of the file, under which is the global configuration of the mybatis framework
Properties:
The resource attribute in the 1/Properties tag can introduce an external property file, resource= "property file path"
<properties resource="user/database.properties"> </properties>
2/Subtags can also be configured under the label of Properties, as follows:
It is worth noting that after adopting the first one, the second one will be covered by the first one regardless of right or wrong.<properties > <property name="driver" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://127.0.0.1:3306/smbms"/> <property name="user" value="root"/> <property name="password" value="mysql"/>--> </properties>
Settings
This tag is used to modify the behavior of the Mybatis runtime: For more information, you can refer to this link: Click Open Link
typeAliases<settings> <setting name="cacheEnabled" value="true" /> //Whether the cache is started or not <setting name="lazyLoadingEnabled" value="true" /> //Whether to start lazy loading <setting name="multipleResultSetsEnabled" value="true" /> </settings>
This tag i can be used to alias java classes for easy use in mapper's xml files
You can name a class or package directly. It's worth noting that frameworks ignore case in mapper's xml return type
....<typeAliases> <typeAlias type="cn.smbms.pojo.User" alias="suser"></typeAlias> <package name="cn.smbms.pojo"></package> </typeAliases>
Environment configuration, environment can configure more than one set, but must default to one set, default value is the id of the environment
Mappers<environments default="one"> <environment id="one"> <transactionManager type="JDBC"></transactionManager> <dataSource type="POOLED"> <property name="driver" value="${driver}"></property> <property name="url" value="${url}"></property> <!--No duplication?????--> <property name="username" value="${user}"></property> <property name="password" value="${password}"></property> </dataSource> </environment> </environments><dataSource type="POOLED">Data source, with three values: UNPOOLED | POOLED | JNDIAmong them: <transactionManager type="JDBC"></transactionManager> transaction manager has two values: JDBC and managed.Data Source Data Source There are three type s [UNPOOLED|POOLED|JNDI]
This tag manages mapper's xml file. If you want the sql statement in mapper to work, you must introduce it here.
<mappers> <mapper resource="user/usermapper.xml"></mapper> <mapper resource="cn/smbms/dao/user/UserMapper.xml"></mapper> </mappers>
In the mapper.xml file
The problem of configuring paths:
In Ide environment, when building a file package, use /, not..