【mybatis】mybatis返回实体类List集合

今天将dao层注解的方法改为xml文件的形式配置,发现在查询的时候只能查出一个字段的信息,其他信息查不出来,但我确实是返回了一个List数组,查文档发现如果是返回实体类List,不应该将resultType中的list返回。

实体类

@Data
public class UserExt {
    
    
   private String userid;
    private String u_name;
    private String u_location;
    private String group;
    private String u_institute;
    private String u_class;

}

注解中的@Data为lombok中的方法,自动生成get,set等方法。

xml文件resultMap

  <resultMap id="UserExtMap" type="com.schedule.model.entity.schedule.UserExt">
        <result column="userid" jdbcType="VARCHAR" property="userid"/>
        <result column="u_name" jdbcType="VARCHAR" property="u_name"/>
        <result column="u_location" jdbcType="VARCHAR" property="u_location"/>
        <result column="group" jdbcType="VARCHAR" property="group"/>
        <result column="u_institute" jdbcType="VARCHAR" property="u_institute"/>
        <result column="u_class" jdbcType="VARCHAR" property="u_class"/>
    </resultMap>

xml 查找方法

<select id="findUserNotByClass" resultMap="UserExtMap">
        SELECT
       u_name,u_location, userid ,GROUP_CONCAT(d_name) AS `group`,u_institute,u_class
        FROM
        v_user
        <where>
            userid NOT IN(SELECT  userid  FROM course  WHERE c_week=#{week} AND 		c_lesson=#{lesson}
            AND (#{startWeek} BETWEEN c_startweek AND c_endweek)
            AND (c_weektype=0 OR MOD(c_weektype,2)=MOD(#{startWeek},2)))

            <if test="useridList !=null and useridList.size>0">
                AND userid IN

                <foreach item="item" index="index" collection="useridList"
                         open="(" separator="," close=")">
                    ${item}
                </foreach>
            </if>

            GROUP BY userid;
        </where>
    </select>

select 中的 resultMap对应的是 resultMap实体类映射类

猜你喜欢

转载自blog.csdn.net/Black_Customer/article/details/108087784