很多时候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>