mybatis返回list


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.完成

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。