mybatis 返回 对象中属性中包含List<String>

1.实体

@Data
public class User {
    private Long userId;
    private String phone;
    private String username;
    private List<String> roles;
}

2.resultMap

<resultMap id="BaseResultMap" type="com.moon.model.User" >
    <id column="user_id" property="userId" jdbcType="BIGINT" />
    <result column="phone" property="phone" jdbcType="VARCHAR" />
    <result column="username" property="username" jdbcType="VARCHAR" />
    <collection property="roles" ofType="java.lang.String">
      <constructor>
        <arg column="roles"/>
      </constructor>
    </collection>
</resultMap>

3.sql 语句

<select id="selectByPhone" resultMap="BaseResultMap" parameterType="java.lang.String" >
    SELECT a.user_id,a.phone,a.username,c.role as roles 
    FROM b_user a , b_user_role b , b_role c
    WHERE a.user_id = b.user_id AND b.role_id = c.role_id and a.phone = #{phone,jdbcType=VARCHAR}
  </select>

相关推荐