映射文件
在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>