long[] 如何在 mybatis的xml如何进行resultmap映射
时间: 2023-08-10 19:07:25 浏览: 142
在 MyBatis 的 XML 中,我们可以使用 `<resultMap>` 标签来进行结果集的映射。对于 long 类型的数组,我们可以使用 `<result>` 标签来进行元素的映射。具体的实现步骤如下:
1. 在 `<resultMap>` 标签中,使用 `<result>` 标签来进行 long 类型数组的映射,使用 `column` 属性来指定列名,使用 `property` 属性来指定 Java 对象中的属性名,如下所示:
```
<resultMap id="longArrayMap" type="com.example.User">
<result column="id_list" property="idList" javaType="long[]" />
</resultMap>
```
2. 在 SQL 查询语句中,使用 `SELECT` 子句指定查询的列名,使用 `AS` 子句给列名取一个别名,别名要与 `<result>` 标签中的 `column` 属性保持一致,如下所示:
```
SELECT id_list AS id_list FROM user WHERE ...
```
3. 在执行查询操作时,使用 `selectList()` 方法并指定 `<resultMap>` 的 id 属性,如下所示:
```
List<User> userList = sqlSession.selectList("com.example.UserMapper.selectUser", null, new RowBounds(0, 10), sqlSession.getConfiguration().getResultMap("longArrayMap"));
```
这样就可以将 long 类型的数组映射到 Java 对象的属性中了。
阅读全文
相关推荐


















