The definition of alias should be defined in sqlMapConfig.xml
Custom Aliases:
Since the type name behind the parameterType is very long, sometimes it is necessary to define an alias. Use the typeAliases tag to put
Example: xxx.x.Person is defined as person (just write person directly in the future)
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <typeAliases> <!-- type: the data type to be defined as an alias --> <typeAlias type="xxx.x.Person" alias = "person"/> </typeAliases> <!-- If the database environment configuration is integrated with spring, it does not need to be configured, it is completely handed over to spring, and the following parts are eliminated. --> < environments default = "development" > <!-- What is the default name here, just call which environment below, that is, you can call a database (MYSQL or Oracle) --> < environment id = "development" > < transactionManager type ="JDBC" /> < dataSource type ="POOLED" > < property name ="driver" value ="com.mysql.jdbc.Driver" /> < property name ="url" value ="jdbc: mysql://localhost:3306/mybatis" /> <property name="username" value="root" /> <property name="password" value="root" /> </dataSource> </environment> </environments> <!-- Manage mapping files for each table resource: import the mapping file, pay attention to the slashes between the packages --> <mappers> <mapper resource="xxx/x/mapper/PersonTestMapper.xml" /> </mappers> </configuration>
Non-custom aliases:
A non-custom alias means that all classes in the JDK use non-custom aliases, and the content of the alias is that all letters of the type are case-insensitive.
for example:
parameterType="java.util.Map"
can be written directly as
parameterType="map"
If it is a wrapper class, you can also use the name of its basic data type.
for example:
parameterType="java.lang.Integer"
can be written as
parameterType="int"
Replace some sql fragments: extract some common sql fragments
<sql id = "column"> is some public information.
<sql id = "column"> person_id,name,gender,person_addr,birthday </sql> <select id="selectPersonAll" resultMap="BaseResultMap" > select <include refid="column"> from person </select>