Mybatis项目配置别名时配置文件遇到的问题
遇到如下问题:Attribute "resource" must be declared for element type "mapper".
解决方案:mybatis 的dtd 文件配置有误
正确的应该是:
<?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> <typeAlias type="com.entity.User" alias="user"/> </typeAliases> <!-- 映射文件,存放sql语句的配置文件 --> <mappers> <mapper resource="com/mybatis/demo/mapper/UserDao.xml" /> </mappers> </configuration>
应该是configuration
这样写之后就不会再报之前那个错误了