Mybatis commonly used XML configuration with disable cache
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE configurationPUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd" ><config> <!-- Settings Must be placed on top--> <settings> <!-- This configuration affects the cached global switches configured in all mappers. Default true --> <setting name="cacheEnabled" value="false" /> <!-- MyBatis uses local cache mechanism to prevent circular references and accelerate duplicate nested queries. The default value is SESSION, in which case all queries executed in a session are cached. If the value is set to STATEMENT, the local session is only used for statement execution, and different calls to the same SqlSession will not share data. --> <setting name="localCacheScope" value="SESSION" /> <!-- Specify the JDBC type for the null value when no specific JDBC type is provided for the parameter. Some drivers need to specify the JDBC type of the column. In most cases, the general type can be used directly, such as NULL, VARCHAR or OTHER. --> <setting name="jdbcTypeForNull" value="OTHER" /> </settings> <!-- MyBatis Connect to MySql database--> <environments default="development"> <environment id="development"> <!-- Using jdbc transaction management--> <transactionManager type="JDBC" /> <!-- Configure database connection pool--> <dataSource type="POOLED"> <property name="driver" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://127.0.0.1:3306/yourdb" /> <property name="username" value="root" /> <property name="password" value="toor" /> </dataSource> </environment> </environments> <!-- All database statement mapping files must be registered here--> <mappers> <mapper resource="dao/mappers/ManagerMapper.xml" /> </mappers></configuration>
The complete configuration of MyBatis is as follows:
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE configurationPUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd" ><config> <!-- Settings Must be placed on top--> <settings> <!-- This configuration affects the cached global switches configured in all mappers. Default true --> <setting name="cacheEnabled" value="true" /> <!-- Global switch for delayed loading. When enabled, all associated objects will be delayed. In a specific relationship, you can override the switch status of the item by setting the fetchType property. Default false --> <setting name="lazyLoadingEnabled" value="true" /> <!-- Whether to allow a single statement to return multiple result sets (requires compatible drivers). Default true --> <setting name="multipleResultSetsEnabled" value="true" /> <!-- Use column labels instead of column names. Different drivers will have different performances in this regard. For details, you can refer to the relevant driver documents or test these two different modes to observe the results of the driver used. Default true --> <setting name="useColumnLabel" value="true" /> <!-- Allows JDBC to support automatic generation of primary keys, and requires driver compatibility. If set to true, this setting forces automatic primary key generation, which works properly although some drivers are not compatible (such as Derby). Default false --> <setting name="useGeneratedKeys" value="false" /> <!-- Specifies how MyBatis should automatically map columns to fields or properties. NONE means canceling the automap; PARTIAL will only automatically map result sets that do not define nested result sets maps. FULL automatically maps any complex result set (necked or not). Default PARTIAL --> <setting name="autoMappingBehavior" value="PARTIAL" /> <!-- Specify the behavior when detects an unknown column (or unknown property type) of automatic mapping target. NONE: Do nothing WARNING: Output warning log (The log level of 'org.apache.ibatis.session.AutoMappingUnknownColumnBehavior' must be set to WARN) FAILING: Fail mapping (Throw SqlSessionException) Default:NONE --> <setting name="autoMappingUnknownColumnBehavior" value="WARNING" /> <!-- Configure the default executor. SIMPLE is an ordinary executor; the REUSE executor will reuse prepared statements; the BATCH executor will reuse statements and perform batch updates. Default SIMPLE --> <setting name="defaultExecutorType" value="SIMPLE" /> <!-- Sets the timeout time, which determines the number of seconds the driver waits for the database to respond. Not Set (null) --> <setting name="defaultStatementTimeout" value="25" /> <!-- Set a prompt value for the number of fetchSize of the driver. This parameter can only be overwritten in query settings. --> <setting name="defaultFetchSize" value="100" /> <!-- Allows the use of paging in nested statements (RowBounds). If allow, set the false. --> <setting name="safeRowBoundsEnabled" value="false" /> <!-- Whether to enable the automatic camel case mapping, that is, a similar mapping from the classic database column name A_COLUMN to the classic Java property name aColumn. --> <setting name="mapUnderscoreToCamelCase" value="false" /> <!-- MyBatis uses local cache mechanism to prevent circular references and accelerate duplicate nested queries. The default value is SESSION, in which case all queries executed in a session are cached. If the value is set to STATEMENT, the local session is only used for statement execution, and different calls to the same SqlSession will not share data. --> <setting name="localCacheScope" value="SESSION" /> <!-- Specify the JDBC type for the null value when no specific JDBC type is provided for the parameter. Some drivers need to specify the JDBC type of the column. In most cases, the general type can be used directly, such as NULL, VARCHAR or OTHER. --> <setting name="jdbcTypeForNull" value="OTHER" /> <!-- Specifies which object's method triggers a delayed load. --> <setting name="lazyLoadTriggerMethods" value="equals,clone,hashCode,toString" /> </settings> <!-- MyBatis Connect to MySql database--> <environments default="development"> <environment id="development"> <!-- Using jdbc transaction management--> <transactionManager type="JDBC" /> <!-- Configure database connection pool--> <dataSource type="POOLED"> <property name="driver" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://127.0.0.1:3306/yourdb" /> <property name="username" value="root" /> <property name="password" value="toor" /> </dataSource> </environment> </environments> <!-- All database statement mapping files must be registered here--> <mappers> <mapper resource="dao/mappers/ManagerMapper.xml" /> </mappers></configuration>
Mybatis official website document: http://www.mybatis.org/mybatis-3/zh/index.html
The above is a detailed explanation of the XML configuration in Mybatis introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for Wulin.com website