(1)在操作mybatis框架进行分页查询操作时,我们要向mybatis.xml文件中设置pageHelper的拦截器,但在我们将
<!-- 设置分页的拦截器--> <plugins> <plugin interceptor="com.github.pagehelper.PageInterceptor"></plugin> </plugins>该行代码放在
<typeAliases>
<!--单独为某个实体类起别名 -->
<typeAlias type="com.wt.entity.Student" alias="u"/>
<!--为指定包下的实体类起别名该别名就是实体类名-->
<package name="com.wt.entity"/>
</typeAliases>该行代码上方时,<configuration>会报红,这时我们将<plugins>文件中的内容放到<typeAliases>下面错误则会消除,这时因为在mybatis.xml文件中存在优先级问题,详情见下图
(2)越靠前的优先级越高,不能写在优先级比自己低的下面
typeAliases优先级>plugins优先级,所以plugins的代码需要写在typeAliases下面。
(3)下方得setting优先级>typeAliases优先级,所以要写在typeAliases上面
完整代码:
<?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>
<settings>
<setting name="cacheEnabled" value="true"/>
</settings>
<typeAliases>
<!--单独为某个实体类起别名 -->
<typeAlias type="com.wt.entity.Student" alias="u"/>
<!--为指定包下的实体类起别名该别名就是实体类名-->
<package name="com.wt.entity"/>
</typeAliases>
<!-- 设置分页的拦截器-->
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor"></plugin>
</plugins>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<!--数据源的配置:name的值固定 value的值要根据客
户自己修改-->
<dataSource type="POOLED">
<property name="driver" value="com.mysql.cj.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/mybatis?serverTimezone=Asia/Shanghai"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</dataSource>
</environment>
</environments>
<!-- 映射-->
<mappers>
<mapper resource="mapper/StudentMapper.xml"/>
</mappers>
</configuration>