In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "the complete configuration steps of Mybatis". In the daily operation, I believe that many people have doubts about the complete configuration steps of Mybatis. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts of "complete configuration steps of Mybatis"! Next, please follow the editor to study!
Complete configuration
Mybatis-config.xml
The first-level configuration property name indicates that properties introduces an external properties file, and the configuration properties can be referenced elsewhere in the whole configuration file; important, the main function is to decouple some global configuration properties used by settings to specify MyBatis, these properties are very important, they will change the runtime behavior of MyBatis; important typeAliases aliases, set a short name for the Java type, easy to use when mapping It is divided into system-defined aliases and custom aliases; typeHandlers can be configured through xml and annotations for conversion between jdbcType and javaType, such as enumerations; no special needs do not need to be adjusted; every time ObjectFactoryMyBatis creates a new instance of the resulting object, it uses object factory (ObjectFactory) to build POJO without modifying the plugins plug-in configuration in most scenarios. MyBatis allows you to intercept calls at some point during the execution of mapped statements.
Environments is used to configure multiple data sources, each data source is divided into database source and transaction configuration; using databaseIdProviderMyBatis in multi-data source environment can execute different statements according to different database vendors, which can be used to support multi-vendor data sources in one system. In most scenarios, there is no need to modify the mappers configuration to introduce the mapper. You can use resource references relative to the classpath, or fully qualified resource locators (including file:/// 's URL), or class names and package names, etc., followed by a thematic description of setting
These are extremely important tuning settings in MyBatis, and they change the runtime behavior of MyBatis. The following table describes the intentions, default values, and so on of the items in the settings.
The setting name describes the valid value default value cacheEnabled globally turns on or off any cache that has been configured by all mappers in the configuration file. Global switch for true and falsetruelazyLoadingEnabled delayed loading. When on, all associated objects are delayed in loading. The switch state of the item can be overridden by setting the fetchType property in a specific association. True, falsefalseaggressiveLazyLoading when turned on, any method call will load all the properties of the object. Otherwise, each property is loaded on demand (see lazyLoadTriggerMethods). True, falsefalse (the default is true in 3.4.1 and earlier) whether multipleResultSetsEnabled allows multiple result sets to be returned by a single statement (driver support is required). True and falsetrueuseColumnLabel use column labels instead of column names. Different drivers will behave differently in this respect. You can refer to the relevant driver documentation or observe the results of the drivers used by testing these two different modes. True and falsetrueuseGeneratedKeys allow JDBC to support automatic generation of primary keys, which requires driver support. If set to true, this setting forces the use of automatically generated primary keys, and some drivers do not support it but still work (such as Derby). True, falseFalseautoMappingBehavior specify how MyBatis should automatically map columns to fields or attributes. NONE means to cancel automatic mapping; PARTIAL only automatically maps result sets that do not define a nested result set mapping. FULL automatically maps any complex result set, whether nested or not. NONE, PARTIAL, FULLPARTIALautoMappingUnknownColumnBehavior specify the behavior of automatically mapping unknown columns (or unknown attribute types) to the target. NONE: no response; WARNING: output reminder log; (the log level of 'org.apache.ibatis.session.AutoMappingUnknownColumnBehavior' must be set to WARN); FAILING: mapping failure (throwing SqlSessionException) NONE, WARNING, FAILINGNONEdefaultExecutorType configure default executor. SIMPLE is a normal executor; REUSE executors reuse preprocessing statements (prepared statements); BATCH executors reuse statements and perform batch updates. SIMPLE, REUSE, and BATCHSIMPLEdefaultStatementTimeout set the timeout, which determines the number of seconds the driver waits for the database to respond. Any positive integer is not set (null) defaultFetchSize sets a prompt value for the driven number of result set fetches (fetchSize). This parameter can only be overridden in query settings. Any positive integer does not set (null) defaultResultSetTypeSpecifies a scroll strategy when omit it per statement settings. (Since: 3.5.2) FORWARD_ONLY, SCROLL_SENSITIVE, SCROLL_INSENSITIVE, DEFAULT (same behavior with 'Not Set') Not Set (null) safeRowBoundsEnabled allow paging (RowBounds) in nested statements. Set to false if allowed. True and falseFalsesafeResultHandlerEnabled allow paging (ResultHandler) to be used in nested statements. Set to false if allowed. Whether true and falseTruemapUnderscoreToCamelCase enable automatic hump naming rule (camel case) mapping, that is, similar mapping from classic database column name A_COLUMN to classic Java attribute name aColumn. True and falseFalselocalCacheScopeMyBatis take advantage of the local caching mechanism (Local Cache) to prevent circular references (circular references) and accelerate repeated 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 used only for statement execution, and different calls to the same SqlSession will not share data. SESSION and STATEMENTSESSIONjdbcTypeForNull specify the JDBC type for null values when no specific JDBC type is provided for the parameter. Some drivers need to specify the JDBC type of the column, and in most cases you can just use the generic type, such as NULL, VARCHAR, or OTHER. JdbcType constant, common values: NULL, VARCHAR or OTHER. OTHERlazyLoadTriggerMethods specifies which object's method triggers a deferred load. A comma-separated list of methods. Equals,clone,hashCode,toStringdefaultScriptingLanguage specifies the default language for dynamic SQL generation. A type alias or fully qualified class name. Org.apache.ibatis.scripting.xmltags.XMLLanguageDriverdefaultEnumTypeHandler specifies the default TypeHandler used by Enum. (added in 3.4.5) A type alias or fully qualified class name. Org.apache.ibatis.type.EnumTypeHandlercallSettersOnNulls specifies whether to call the setter (put when map object) method of the mapping object when the result set value is null, which is useful when initializing depending on the Map.keySet () or null value. Note that the basic types (int, boolean, etc.) cannot be set to null. True, falsefalsereturnInstanceForEmptyRow when all columns of the returned row are empty, MyBatis returns null by default. When this setting is enabled, MyBatis returns an empty instance. Note that it also applies to nested result sets, such as collections or associations. (added in 3.4.2) true, falsefalselogPrefix specify that MyBatis is added to the prefix of the log name. Any string does not set logImpl to specify the specific implementation of the log used by MyBatis. If it is not specified, it will be found automatically. SLF4J, LOG4J, LOG4J2, JDK_LOGGING, COMMONS_LOGGING, STDOUT_LOGGING, NO_LOGGING do not set proxyFactory to specify the proxy tool that Mybatis uses to create objects with lazy loading capabilities. CGLIB, JAVASSISTJAVASSIST (MyBatis 3.3 +) vfsImpl specifies the fully qualified name of the class that implements the custom VFS implementation of VFS, separated by commas. UseActualParamName is not set to allow the name in the method signature to be used as the statement parameter name. In order to use this feature, your project must be compiled in Java 8 with the-parameters option. (added in 3.4.1) true and falsetrueconfigurationFactory specify a class that provides an instance of Configuration. This returned Configuration instance is used to load the deferred load property value of the deserialized object. This class must contain a method signed static Configuration getConfiguration (). (added in 3.2.3) Type alias or full class name. Environment is not set
The environment element is the beginning of configuring a data source, and the attribute id is its unique identity
TransactionManager
The transactionManager element configures database transactions, where the type attribute can be configured in three ways:
Jdbc, using jdbc to manage transactions
Managed, which manages transactions as a container and is used in JNDI data sources
Custom, custom database transaction management method
DataSource
The dataSource element configures the data source connection information. The type attribute is configured by connecting to the database. There are four ways to configure it:
UNPOOLED connection without connection pool
POOLED uses connection pooling connections
JNDI uses JNDI data sources
Custom data source
Mappers
Now that the behavior of MyBatis has been configured by the above elements, we now need to define the SQL mapping statement. But first we need to tell MyBatis where to find these statements. Java doesn't provide a good way to find it automatically, so the best way is to tell MyBatis where to find the mapping file. You can use resource references relative to the classpath, or fully qualified resource locators (including file:/// 's URL), or class names and package names, etc. For example:
With the resource reference under classPath, the study on "the complete configuration steps of Mybatis" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.