This is the 29th day of my participation in Gwen Challenge
Sqlmapconfig. XML configuration file
I. Configuration content
- Sqlmapconfig. XML is configured in the following order:
- Properties
- Settings global configuration parameters
- typeAliases
- typeHandlers
- objectFactory
- Plugins
- Environments (Environment collection attributes object)
- Environment (Environment child property object)
- transactionManager
- A dataSource
- Mappers (mapper)
Properties properties
- That is, use the properties property in the core configuration file to configure the database configuration
<properties resource="db.properties"/>
Copy the code
Three, Settings,
- Mybatis global configuration parameters, global parameters will affect the operation behavior of MyBatis.
- Mainly used for thread optimization, caching, etc
TypeAliases (typeAliases)
- That is, the name of the input parameter set in the mapping file can be customized, rather than write a fixed full path name
- The underlying type is already aliased
- That is to say, the typed name is different, but the type is the same
The alias map is of type _bytebyte
_long long
_short short
_int int
_integer int
_double double
_float float
_boolean boolean
string String
byte Byte
long Long
short Short
int Integer
integer Integer
double Double
float Float
boolean Boolean
date Date
decimal BigDecimal
bigdecimal BigDecimal
Copy the code
- Custom alias
- In the core configuration file
- Single alias definition
- In usermapper. XML, for example, if the output type is cn.sju.User, the output type can be aliased as User
<typeAliases> <! -- Single alias definition --> <typeAlias alias="user" type="cn.itcast.mybatis.po.User"/> Copy the code
- Batch alias definition
- The alias is then the class name of the class
<typeAliases> <! -- Batch alias definition, scan the entire package under the class alias name (uppercase or lowercase can be used) --> <package name="cn.itcast.mybatis.po"/> <package name="Other bags"/> </typeAliases> Copy the code
typeHandlers
- Type handlers are used for Java type and JDBC type mappings as follows:
<select id="findUserById" parameterType="int" resultType="user">
select * from user where id = #{id}
</select>
Copy the code
- Mybatis comes with a type processor that basically meets daily needs and does not need to be defined separately.
Mappers
- Use the mapping file name mapping
<mapper resource="sqlmap/User.xml" />
Copy the code
- Use full path mapping
<mapper url="file:///D:\workspace_spingmvc\mybatis_01\config\sqlmap\User.xml" />
Copy the code
- Use the interface classpath
- This method requires:
- Mapper The name of an interface is the same as the name of a mapper mapping file
- The two files are in the same directory
- This method requires:
<mapper class="cn.itcast.mybatis.mapper.UserMapper"/>
Copy the code
- Use the package name
- role
- Registers all mapper interfaces under the specified package
- This method requires:
- Mapper The name of an interface is the same as the name of a mapper mapping file
- The two files are in the same directory
- role
<package name="cn.itcast.mybatis.mapper"/>
Copy the code