mybatis查询结果包含List<String> 应该怎么写resultMap
时间: 2025-02-17 21:21:48 浏览: 8
在MyBatis中,如果你想要从数据库查询的结果集中获取一个List
<resultMap id="myResultMap" type="YourEntity">
<!-- 这里YourEntity是你实体类的名字 -->
<id property="id" column="id"/>
<!-- 如果你想返回的是一个List<String>,可以这样定义 -->
<result property="strings" column="your_column_name" javaType="java.util.List" jdbcType="VARCHAR"/>
</resultMap>
<!-- 在你的select语句中引用这个resultMap -->
<select id="selectStrings" resultMap="myResultMap">
SELECT your_column_name FROM your_table
</select>
然后,在你的Service层或者Repository接口中,你可以通过List<String>
来接收这个列表:
public interface YourMapper {
List<String> selectStrings();
}
public class YourServiceImpl implements YourMapper {
@Override
public List<String> selectStrings() {
return sqlSession.selectList("selectStrings");
}
}
相关推荐



















