在MyBatis中,resultType和resultMap都用于描述查询结果如何映射到Java对象。它们之间有一些关键区别:
示例:
SELECT * FROM users
</select>
<resultMap>
元素及其子元素(如<id>
、<result>
、<association>
、<collection>
等)来描述映射规则。示例:
<id property="id" column="id"/>
<result property="username" column="username"/>
<result property="email" column="email"/>
<association property="address" javaType="com.example.Address">
<result property="street" column="street"/>
<result property="city" column="city"/>
</association>
</resultMap><select id="selectUsers" resultMap="userResultMap">
SELECT * FROM users
</select>
总结: