zoukankan      html  css  js  c++  java
  • 关于mybatis如何返回list<Object>类型的解决

    很多时候HashMap会满足不了我们的需求,所以我们可以使用自定义的方式来定义属于自己的list集合。

    首先,直接在配置文件中定义一个关于student的list

    type 写相关model的全路径。id是这个resultMap的唯一标识,方便待会我们调用这个定义好的 resultMap

     <resultMap type="model.Student" id="studentList">
          <result column="stu_id" property="id"/>
          <result column="ope_id"  property="opeId"/>
          <result column="stu_no"  property="stuNo"/>
          <result column="stu_sex" property="stuSex"/>
          <result column="stu_name" property="stuName"/>
          <result column="stu_birth"  property="stuBirth"/>
          <result column="stu_pic" property="stuPic"/>
          <result column="cla_id"  property="claId"/>        
    </resultMap>

    然后把上面的id,写在你相关操作数据库的语句中的 resultMap中。。这就可以实现了。。

    <!-- select 区域  -->
        <select id="selectStudent" parameterType="model.Student" resultMap="studentList">
              SELECT * FROM student
              <where>
                  <if test="id != null">
                      stu_id = #{id}
                  </if>
                  <if test="opeId != null">
                      And ope_id = #{opeId}
                  </if>
                  <if test="stuNo != null">
                      And stu_no = #{stuNo}
                  </if>
                  <if test="stuSex != null">
                      And stu_sex = #{stuSex}
                  </if>
                  <if test="stuName != null">
                      And stu_name = #{stuName}
                  </if>
                  <if test="stuBirth != null">
                      And stu_birth = #{stuBirth}
                  </if>
                  <if test="stuPic != null">
                      And stu_pic = #{stuPic}
                  </if>
                  <if test="claId != null">
                      And cla_id = #{claId}
                  </if>         
              </where>
        </select>
  • 相关阅读:
    Windows下Yarn安装与使用
    论文阅读Graph Convolutional Matrix Completion
    如何快速查询中科院JCR分区和汤森路透JCR分区
    Implement GAN from scratch
    PyCharm将main.py解析成text文件的解决方法
    理解PyTorch的自动微分机制
    mcast_set_if函数
    mcast_get_if函数
    mcast_unblock_source函数
    mcast_block_source函数
  • 原文地址:https://www.cnblogs.com/tjc1996/p/7093892.html
Copyright © 2011-2022 走看看