xml映射文件的方式操作mybatis
映射文件
在Java spring中使用mybatis有两种方式,一种是注释的方式,一种是xml映射文件的方式。在简单的功能需求可以使用注释,方便简洁。而在大的功能逻辑上,更推荐使用xml映射文件,方便管理且结构清晰。
首先xml文件结构上必须要与接口的接口相同,名称相同。
在xml文件中,设置基本框架代码,在mybatis官方文档中可以复制。
例如:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.itheima.mapper.EmpMapper"><select id="querryList" resultType="com.itheima.pojo.Emp">select * from tb_emp<where>gender = #{id};</where>
</select>
</mapper>