Mybatis returns that the attribute in the object contains list


1. entity

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


<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">
        <arg column="roles"/>

3.sql statement

<select id="selectByPhone" resultMap="BaseResultMap" parameterType="java.lang.String" >
    SELECT a.user_id,,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 = #{phone,jdbcType=VARCHAR}