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

 

转载于:https://www.cnblogs.com/nelson-hu/p/6381679.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值