在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>
總結: