在Java中,可以通过以下步骤使用ResultMap获取查询结果:
示例代码如下:
<resultMap id="userResultMap" type="User">
<id property="id" column="id"/>
<result property="name" column="name"/>
<result property="age" column="age"/>
</resultMap>
<select id="getUserById" resultMap="userResultMap">
SELECT id, name, age FROM user WHERE id = #{id}
</select>
User user = sqlSession.selectOne("getUserById", 1);
public class User {
private int id;
private String name;
private int age;
// Getters and setters
}
通过以上步骤,就可以使用ResultMap获取查询结果,并将其转换为实体类对象。