This is the 29th day of my participation in Gwen Challenge

Sqlmapconfig. XML configuration file

I. Configuration content

  1. 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

  1. 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,

  1. Mybatis global configuration parameters, global parameters will affect the operation behavior of MyBatis.
  2. Mainly used for thread optimization, caching, etc

TypeAliases (typeAliases)

  1. That is, the name of the input parameter set in the mapping file can be customized, rather than write a fixed full path name
  2. 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
  1. Custom alias
    • In the core configuration file
    1. 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
    1. 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

  1. 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
  1. Mybatis comes with a type processor that basically meets daily needs and does not need to be defined separately.

Mappers

  1. Use the mapping file name mapping
<mapper resource="sqlmap/User.xml" />
Copy the code
  1. Use full path mapping
<mapper url="file:///D:\workspace_spingmvc\mybatis_01\config\sqlmap\User.xml" />
Copy the code
  1. Use the interface classpath
    1. 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
<mapper class="cn.itcast.mybatis.mapper.UserMapper"/>
Copy the code
  1. Use the package name
    1. role
      • Registers all mapper interfaces under the specified package
    2. 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
<package name="cn.itcast.mybatis.mapper"/>
Copy the code