前言:ResultMap是讓XML中SQL語句的返回值能夠映射到實體類sql
正文:mybatis
1,實體類this
Basic(名字隨便取的)spa
public class Basic { private String id; public String getId() { return id; } public void setId(String id) { this.id = id; } }
繼承Basic類的Person類code
public class Person extends Basic { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } }
2,在mybatis的sql.xml裏就能夠這樣定義ResultMapxml
<resultMap id="BasicMap" type="com.bf.vo.Basic"> <result column="ID" jdbcType="VARCHAR" property="id" /> </resultMap> <resultMap id="PersonMap" type="com.bf.vo.Person" extends="BasicMap"> <result column="NAME" jdbcType="VARCHAR" property="name" /> </resultMap> <select id="selectExample" resultMap="PersonMap"> SELECT ID, NAME FROM XX_TABLE </select>