1.實體java
@Data public class User { private Long userId; private String phone; private String username; private List<String> roles; }
2.resultMapsql
<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 語句code
<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>