在MyBatis中,可以使用ResultMap來獲取查詢結果中列的值。具體步驟如下:
<resultMap id="userResultMap" type="User">
<id property="id" column="user_id"/>
<result property="username" column="user_name"/>
<result property="email" column="user_email"/>
</resultMap>
<select id="selectUser" resultMap="userResultMap">
SELECT user_id, user_name, user_email
FROM users
WHERE user_id = #{id}
</select>
User user = sqlSession.selectOne("selectUser", 1);
System.out.println("User ID: " + user.getId());
System.out.println("Username: " + user.getUsername());
System.out.println("Email: " + user.getEmail());
通過以上步驟,就可以在MyBatis中獲取查詢結果中列的值。