mapper代理dao实现,并且程序能够正常运行,并且运行结果符合预期。
接下来问题就出现了,定义的实体类对象完全限定名称太长,我对它取别名时候 mybatis-config.xml 的<configuration>报错:
The content of element type "configuration" must match
"(properties?,settings?,typeAliases?,typeHandlers?,objectFactory?,objectWrapperFactory?,reflectorFactory?,plugins?,environments?,databaseIdProvider?,mappers?)".
后来发现mybatis-config.xml标签必须按照提示的顺序写。
这样写就正确了。
配置映射文件时,可以使用resource定位mapper映射文件的位置,
还可以使用class,用mapper接口映射
<configuration>
<!-- 加载config/db.properties中的属性值 -->
<properties resource="config/db.properties">
</properties>
<typeAliases>
<typeAlias type="zzu.qg.mybatis.entity.User" alias="user"/>
</typeAliases>
<environments default="development">
<environment id="development">
<!-- 使用jdbc事务管理,目前由mybatis来管理 -->
<transactionManager type="JDBC"/>
<!-- 数据库连接池,目前又mybatis来管理 -->
<dataSource type="POOLED">
<property name="driver" value="${sqlserver_driver}"/>
<property name="url" value="${sqlserver_url}"/>
<property name="username" value="${sqlserver_userName}"/>
<property name="password" value="${sqlserver_password}"/>
</dataSource>
</environment>
</environments>
<!-- 映射文件 -->
<mappers>
<mapper resource="zzu/qg/mybatis/mapper/User.xml"/>
<mapper class="zzu.qg.mybatis.mapper.UserMapper"/>
<!-- <mapper resource="zzu/qg/mybatis/mapper/UserMapper.xml"/> -->
</mappers>
</configuration>
批量起别名有一种更省事的方法
<package name="zzu.qg.mybatis.entity"/> 为实体包里所有类起别名,,直接使用类名就可以(首字母大写,小写都可以)
批量映射文件
<typeAliases>
<mapper class="zzu.qg.mybatis.mapper"/> 配置该包里所有的映射文件
</typeAliases>
下面表引自:https://blog.youkuaiyun.com/eson_15/article/details/51604171?utm_source=copy