public class User { private int id; private String username; private String hashedPassword; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getHashedPassword() { return hashedPassword; } public void setHashedPassword(String hashedPassword) { this.hashedPassword = hashedPassword; } }
<select id="selectUsers" parameterType="int" resultType="com.someapp.model.User"> select id, username, hashedPassword from some_table where id = #{id} </select>
<select id="selectUsers" parameterType="int" resultType="User"> select user_id as "id", user_name as "userName", hashed_password as "hashedPassword" from some_table where id = #{id} </select>
<resultMap id="userResultMap" type="User"> <id property="id" column="user_id" /> <result property="username" column="username"/> <result property="password" column="password"/> </resultMap> <select id="selectUsers" parameterType="int" resultMap="userResultMap"> select user_id, user_name, hashed_password from some_table where id = #{id} </select>
看出來了吧,resultType和resultMap都映射到了User對象中java