1 Model类
public class Vo { /** * this is used for receive data partly from table user_question_section */ private Integer commonScore; private Integer questionSectionDef; /** * @return the commonScore */ public Integer getCommonScore() { return commonScore; } /** * @param commonScore the commonScore to set */ public void setCommonScore(Integer commonScore) { this.commonScore = commonScore; } /** * @return the questionSectionDef */ public Integer getQuestionSectionDef() { return questionSectionDef; } /** * @param questionSectionDef the questionSectionDef to set */ public void setQuestionSectionDef(Integer questionSectionDef) { this.questionSectionDef = questionSectionDef; } }
2.interface 接口类
List<Vo> selectUserSectionsScore(Integer userId);
3.mapper文件中
1.首先定义一个resultmap,type指向你的model类
<resultMap id="SectionDefAndScoreMap" type="com.kingland.otp.models.Vo"> <result column="score" jdbcType="INTEGER" property="commonScore"/> <result column="def_section_id" jdbcType="INTEGER" property="questionSectionDef"/> </resultMap>
2.select语句中,要用resultMap指明你定义的resultmap
<select id="selectUserSectionsScore" parameterType="INTEGER" resultMap="SectionDefAndScoreMap"> select usr.score,qs.def_section_id from ui.user_question_section_xref usr inner join ui.question_section qs on usr.question_section_id = qs.section_id where usr.user = #{0,jdbcType=INTEGER} </select>
4.完成