03.Mybatis optimization

Code dynamic proxy way for further optimization:

1. conf.xml file configuration information to the database pulled out in the form of db.properties

driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/person?serverTimezone=UTC
username=root
password=root
< The Configuration > 
   < properties Resource = "db.properties" /> // pulled out to load the properties file come in < Environments default = "Development" > < Environment the above mentioned id = "Development" > < transactionManager of the type = "JDBC" /> < the dataSource type = "the POOLED" > < Property name = "Driver" value = "$ {Driver}" /> // referenced manner similar expressions el <property name="url" value="${url}"/>  
  
    
      
      
        
        
        <property name="username" value="${username}"/>
        <property name="password" value="${password}"/>
      </dataSource>
    </environment>
  </environments>
  <mappers>
    <mapper resource="com/offcn/mapper/personMapper.xml"/>
  </mappers>
</configuration>

2. Configure the global parameters :( as an entry generally does not set global parameters)

<configuration>
    <properties resource="db.properties" />
    <!-- 设置全局参数
    <settings>
        <setting name="cacheEnabled" value="false" />
        <setting name="lazyLoadingEnabled" value="false" />
    </settings> 

All global parameters:

Setting parameters description Valid values Defaults
cacheEnabled All mapper affected by the configuration of the cache global switch configuration. true | false true
lazyLoadingEnabled Delay global switch loaded. When turned on, all associations will be delayed loading. Specific association may be provided by fetchType to cover the switching state of the property. true | false false
aggressiveLazyLoading When turned on, any method invocation will load all the object's properties. Otherwise, each property will be loaded on demand (refer lazyLoadTriggerMethods ). true | false false (true in ≤3.4.1)
multipleResultSetsEnabled Whether to allow a single statement to return multiple result sets (requires compatible drive). true | false true
useColumnLabel Use the column label instead of the column name. Different drivers have different performance in this regard, specific reference documentation associated drive or driven to observation by the test used two different modes. true | false true
useGeneratedKeys JDBC support allows automatic generation of primary keys, is necessary to drive compatibility. If set to true, the setting forces used to automatically generate the primary key, some drivers may not be compatible but still work (such as Derby). true | false False
autoMappingBehavior MyBatis specifies how to automatically map columns fields or properties. NONE means cancel the automatic mapping; will automatically map the PARTIAL no result set mappings defined nested results. FULL automatically mapped arbitrarily complex set of results (whether or not nested). NONE, PARTIAL, FULL PARTIAL
autoMappingUnknownColumnBehavior Automatically map the specified target discovery Unknown column (or unknown attribute type) behavior.
  • NONE : without any reaction
  • The WARNING : Output alert log ( 'org.apache.ibatis.session.AutoMappingUnknownColumnBehavior' log level must be set to  WARN )
  • Failing : mapping failed (throws  SqlSessionException )
NONE, WARNING, FAILING NONE
defaultExecutorType The default configuration of the actuator. SIMPLE is an ordinary actuator; REUSE executor will reuse prepared statements (prepared statements); BATCH executor reuses the statement and perform batch updates. SIMPLE REUSE BATCH SIMPLE
defaultStatementTimeout Set the timeout, it decided to drive the number of seconds to wait for a database response. Any positive integer Not Set (null)
defaultFetchSize Result set to drive acquires the number (the fetchSize) provided a prompt value. This parameter can only be overwritten in the query settings. Any positive integer Not Set (null)
safeRowBoundsEnabled It allows the use of tabs (RowBounds) in a nested statements. If a permit is set to false. true | false False
safeResultHandlerEnabled Tab allows the use of (the ResultHandler) in a nested statements. If a permit is set to false. true | false True
mapUnderscoreToCamelCase Whether to open automatically hump naming convention (camel case) mapping that maps the column names A_COLUMN similar to the classic Java property name aColumn from classic database. true | false False
localCacheScope MyBatis use of local caching mechanism (Local Cache) to prevent circular references (circular references) and accelerated repeat nested queries. The default is SESSION, this case will cache all queries executed in a session. If the setting is STATEMENT, local session only on the statement is executed, different calls to the same SqlSession will not share data. SESSION | STATEMENT SESSION
jdbcTypeForNull When no specific JDBC type parameter specifies the JDBC type is null. Some drivers need to specify the JDBC type column, in most cases directly to a general type, such as NULL, VARCHAR, or OTHER. JdbcType enumeration. Most common are: NULL, VARCHAR and OTHER OTHER
lazyLoadTriggerMethods Specify which object's method to trigger a delay in loading. A method name list separated by commas equals,clone,hashCode,toString
defaultScriptingLanguage 指定动态 SQL 生成的默认语言。 A type alias or fully qualified class name. org.apache.ibatis.scripting.xmltags.XMLLanguageDriver
defaultEnumTypeHandler Specifies the TypeHandler used by default for Enum. (Since: 3.4.5) A type alias or fully qualified class name. org.apache.ibatis.type.EnumTypeHandler
callSettersOnNulls 指定当结果集中值为 null 的时候是否调用映射对象的 setter(map 对象时为 put)方法,这对于有 Map.keySet() 依赖或 null 值初始化的时候是有用的。注意基本类型(int、boolean等)是不能设置成 null 的。 true | false false
returnInstanceForEmptyRow 当返回行的所有列都是空时,MyBatis默认返回null。 当开启这个设置时,MyBatis会返回一个空实例。 请注意,它也适用于嵌套的结果集 (i.e. collectioin and association)。(从3.4.2开始) true | false false
logPrefix 指定 MyBatis 增加到日志名称的前缀。 Any String Not set
logImpl 指定 MyBatis 所用日志的具体实现,未指定时将自动查找。 SLF4J | LOG4J | LOG4J2 | JDK_LOGGING | COMMONS_LOGGING | STDOUT_LOGGING | NO_LOGGING Not set
proxyFactory 指定 Mybatis 创建具有延迟加载能力的对象所用到的代理工具。 CGLIB | JAVASSIST JAVASSIST (MyBatis 3.3 or above)
vfsImpl 指定VFS的实现 自定义VFS的实现的类全限定名,以逗号分隔。 Not set
useActualParamName 允许使用方法签名中的名称作为语句参数名称。 为了使用该特性,你的工程必须采用Java 8编译,并且加上-parameters选项。(从3.4.1开始) true | false true
configurationFactory 指定一个提供Configuration实例的类. 这个被返回的Configuration实例是用来加载被反序列化对象的懒加载属性值. 这个类必须包含一个签名方法static Configuration getConfiguration(). (从 3.2.3 版本开始) 类型别名或者全类名. Not set

Guess you like

Origin www.cnblogs.com/man-tou/p/11335048.html